Push to one remote repository only in a multi-remote repository local repository.

huangapple go评论89阅读模式
英文:

Push to one remote repository only in a multi remote repository local repository

问题

Using an old version of Git Extensions (2.49)

我刚刚尝试从次要远程存储库中挑选多个更改到我的本地存储库和主要远程存储库。

Doing so, I added the second remote repository over
"Repository" -> "Remote repositories" -> "New"
and so on.

这样做,正如预期的那样,导致Git扩展显示了主要和次要的所有远程树和所有更改。我能够在相同的视图中轻松挑选和合并来自次要的更改,显示为不同的远程分支。一切看起来都很正常,我能够在本地创建新的功能分支并将其推送到主要远程存储库。

Later, after a fetch all, I found out the secondary remote repository has also "received" the full tree of the primary. Even from a different local repository, where just the secondary is linked in and used, I still see the whole data of primary now.

稍后,在执行完所有的获取操作后,我发现次要远程存储库也“接收到”了主要存储库的完整树。即使在不同的本地存储库中,只链接并使用了次要存储库,我现在仍然看到了主要存储库的全部数据。

That lead to big troubles for me and I am currently trying to find out what was going on.

这导致了我很大的困扰,我目前正在尝试弄清楚发生了什么事情。

In the "Push" dialog, every time there is this dropdown where I can select one remote repository. Alternatively, it is possible to push to an URL but this I have not used. I am pretty sure that I have always selected the primary repository there. But still, all changes and even the whole history was pushed to secondary.
I would have expected that when I select one remote repository at a push, that the data really just goes to that repository and no other remote.

在“Push”对话框中,每次都有一个下拉菜单,我可以在其中选择一个远程存储库。或者,也可以推送到一个URL,但我没有使用过这个选项。我非常确定我一直在那里选择主要存储库。但是仍然将所有更改甚至整个历史记录都推送到了次要存储库。
我本来希望在进行推送时,当我选择一个远程存储库时,数据只会被发送到该存储库,而不会发送到其他远程存储库。

Question 1:

What was my mistake?

问题1:

我犯了什么错误?

Question 2:

How can I fix the secondary repository and remove everything that was copied from primary?

问题2:

我如何修复次要存储库并删除从主要存储库复制的所有内容?

Can I somehow choose one commit and remove it and all it's childrens? This should be a method to remove the primary branch from secondary.

我是否可以以某种方式选择一个提交并删除它以及它的所有子提交?这应该是从次要存储库中删除主要分支的方法。

I really hope you can help since I was working in a team and now the whole repo is a total mess due to my changes. xD

我真的希望你能帮助,因为我当时正在一个团队中工作,现在整个存储库因为我的更改而变得一团糟。xD

Edit 1:

Question 3:

For next time, is it possible to add a secondary remote repository as read only? That would have prevented that problem.

编辑1:

问题3:

下次是否可以将次要远程存储库添加为只读?这将可以防止这个问题发生。

英文:

Using an old version of Git Extensions (2.49)

I just tried to cherry pick multiple changes from a secondary remote repository to my local reposity and primary remote repository.

Doing so, I added the second remote repository over
"Repository" -> "Remote repositories" -> "New"
and so on.

This lead, as expected, to Git Extensions to show both remote trees and all changes from primary and secondary.
I was able to easily cherry pick and merge my changes from secondary in the same view, shown as different remote branches. First everything looked fine and I was able to create new feature branches on local and do the work and push to primary remote.

Later, after a fetch all, I found out the secondary remote repository has also "received" the full tree of the primary. Even from a different local repositry, where just the secondary is linked in and used, I still see the whole data of primary now.

That lead to big troubles for me and I am currently trying to find out what was going on.

In the "Push" dialog, every time there is this dropdown where I can select one remote repository. Alternatively, it is possible to push to an URL but this I have not used. I am pretty sure that I have always selected the primary repository there. But still, all changes and even the whole history was pushed to secondary.
I would have expected that when I select one remote repository at a push, that the data really just goes to that repository and no other remote.

Question 1:

What was my mistake?

Question 2:

How can I fix the secondary repository and remove everything that was copied from primary?

Can I somehow choose one commit and remove it and all it's childrens? This should be a method to remove the primary branch from secondary.

I really hope you can help since I was working in a team and now the whole repo is a total mess due to my changes. xD

Thanks.

Edit 1:

Question 3:

For next time, is it possible to add a secondary remote repository as read only? That would have prevented that problem.

答案1

得分: 0

你可能已经将更改推送到了"secondary",仅获取操作不会推送任何内容。

在终端工作的一个优点是你可以获得你已运行命令的历史记录。

可能发生的情况是推送到了远程跟踪分支:如果你在具有与"secondary"有远程跟踪的本地分支上,并且执行了没有参数的 git push 命令,那可能会推送到"secondary"。

不管怎样,很难说究竟发生了什么,因为我认为你自己也很难记住发生了什么(再次强调,在终端运行命令的优势之一)。


但是关于如何修复它:

  • 准备好你想要在本地存储库中看到的分支(按照你想要在"secondary"中的样子):branch_on_secondary

  • 明确地将其强制推送到"secondary":

    git push -f secondary branch_on_secondary:branch_on_secondary

现在你已经将分支恢复到了远程的secondary。请注意,任何拥有污染分支副本的人可能会在未来进行推送,并且你将再次回到branch_on_secondary的错误状态。你需要告诉任何可能拥有这种错误分支的人更新他们的本地副本:

git fetch secondary branch_on_secondary:branch_on_secondary

如果"错误"提交存在于secondary上的其他分支上,你需要为每个这样的分支进行清理。


如果你想要从"secondary"完全删除一个分支,可以通过将"什么都不推送" 到远程分支来实现:

git push -f secondary :branch_to_delete_on_secondary

这可能是你想要删除已经传送到"secondary"存储库的primary_branch分支的方法。


你的想法是正确的,从"secondary"获取分支,然后挑选提交(如果你无法使用整个分支),然后将其推送到"primary"。你只需要确保不将其再次推送回"secondary"。

英文:

You probably did a push to secondary, fetching alone would not push anything.

One advantage of working in the terminal: you get the history of the commands you've run.

What might have happened is a push to a remote tracking branch: if you were on a local branch with remote tracking to secondary, and did a git push without arguments, that would probably push to secondary.

Anyway, it's hard to say what really happened, because I think you yourself have a hard time remembering exactly what happened (again, an advantage of running in terminal).


But on how to fix it:

  • get the branch you want to look "untouched" (how you want it to be in secondary) ready in your local repo. branch_on_secondary

  • force push it explicitly to secondary:

    git push -f secondary branch_on_secondary:branch_on_secondary

You've now restored the branch on the remote secondary. Note that anyone with a copy of the polluted branch might do a push in the future, and you'll get back to the erroneous state for branch_on_secondary. You need to tell anyone who might have such an erroneous branch to update their local copy:

git fetch secondary branch_on_secondary:branch_on_secondary

If the "wrong" commits are on other branches on secondary, you need to clean up for every such branches.


If you want to totally remove a branch from secondary, you do that by pushing "nothing" to that remote branch:

git push -f secondary :branch_to_delete_on_secondary

This might be what you want to remove a branch primary_branch that made its way to repo secondary.


You were thinking right, getting the branch from secondary, then cherry-picking commits (if you can't use a whole branch) into local, then pushing that into primary. You just need to make sure to not push that back to secondary.

答案2

得分: 0

抱歉造成混淆。我想我找到了问题所在。

正如我所说,我使用的是一个非常旧的 Git Extensions 版本(2.49)。看起来这个版本非常有 bug 或者与我的设置不兼容。

问题在于仓库配置对话框窗口的行为很奇怪。
我在那里添加了第二个仓库,后来我发现,原始远程仓库也改成了与次要仓库相同的 URL。这导致主要和次要的两个配置实际上都指向了次要的 URL,我在推送时推送到了次要仓库。拉取后,GUI 看起来好像同时推送到了主要和次要仓库。

在得出这个结论后,我试着调整了这个对话框,它的行为非常奇怪。有时 URL 在保存后会被删除,有时它会将 URL 保存到不同的远程仓库条目,有时又可以正常工作。很奇怪。

我决定选择了非法途径(公司政策),下载了最新的 Git Extensions 便携版。在这里一切都运行得非常完美,符合预期。

甚至次要仓库也修复了。它是一个 Gerrit 服务器,在那里我能够从次要仓库中选择不小心推送的分支。之后,整个孤立的提交树再次消失了。

所以现在一切都修复好了。:-D

感谢你的帮助。

英文:

Sorry for the confusion. I think I found out what was going on.

As said, I was using a really old version of Git Extensions (2.49). It seems that this version was very buggy or has compatibility issues with my setup.

The problem was that the Repository config dialog window was behaving strange.
I added the second repository there and later I found out, that the original remote repository was also changed the same URL as the secondary. This lead to the situation that both configs, primary and secondary were pointing in the reality to the secondary URL and I was pushing to secondary. After a fetch the GUI looked like it was pushed to both, prim and second.

After that conclusion I played around with this dialog and it just behaves completely strange. Sometimes the URL gets removed after saving, sometimes it saves the URL to a different remote repository entry, sometimes it works. Strange.

I decided to go the illegal path (company policy) and downloaded the newest portable variant of Git Extensions. Here everything works perfectly fine and as expected.

Even the secondary repo was fixed. It is a Gerrit server and there you have an web frontend where I was able to choose the accidentially pushed branches from secondary. After that, the whole orphan commit tree disappeard again.

So everything is fixed now. Push to one remote repository only in a multi-remote repository local repository.

Thanks for the help.

huangapple
  • 本文由 发表于 2023年5月25日 15:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定