异国情调的GIT合并

发布于 2025-01-20 05:21:20 字数 544 浏览 3 评论 0原文

因此,这里的情况可能并不常见。我想对如何最好地进行一些想法。我正在尝试合并两个基于共同代码基础的项目。直到一点。到目前为止,如果提交历史将共享相同的历史,那么一切都很好。我的意思是什么,好吧……

最初的项目是一个墨西哥存储库,但在某个时候,Bitbucket决定放弃对Mercurial的支持。这就是原始项目切换到GitHub的点。但是我已经完成了我之前一直维护的叉子的开关。因此,现在有两个版本的同一库具有完全相同的提交历史记录,直到出现叉子为止。但是,每对委员会的提交都不会少,因此Git认为没有共同的历史。自叉以来,原始库没有任何重大更新,只是小修复。我的叉子有一些重大变化。那该怎么做。 Oginal Project负责人最近与我联系了有关接管存储库的可能。我的叉子从不上游的事情的原因是,从我的说法中,另一侧没有时间。我猜足够公平,在开源中,志愿者没有任何义务。如果我要接管存储库,我想再次合并项目。

关于如何最好地做到这一点的想法吗?我正在考虑将主人重命名为掌握,并使用我的叉子的历史,该历史已适用于新的大师。之后,我会樱桃从叉子上挑选出Master Old的补丁。但这可能会导致人们下次吉特拉的问题。有没有更好的方法来应对这种情况?

So here is a situation that is probably not common. And I would like some thoughts on how to best proceed. I am trying to merge two projects that build upon a common code base. Up to a point. So far so good if the commit history would share the same history. What do I mean by that, well …

Originally the project was a mercurial repository, but at some point bitbucket decided to drop support for mercurial. That was the point at which the original project switched to github. But I had done the switch for the fork I have been maintaining earlier. So now there are two version of the same library that have exactly the same commit history up until the fork happend. But never the less each pair of commits has different hashes so git thinks there is no shared history. The original library has not had any major updates since the fork, just small fixes. My fork has had some major changes. So what to do. The orginal project lead recently contacted me about possible taking over the repository. The reason my fork never upstreamed things was that from what I could tell, the other side just did not have the time. Fair enough I guess, in open source the volunteers are not obligated to anything. If I am going to take over the repository I would like to merge the projects again.

Any thoughts on how best to do this? I am thinking of renaming the master to master-old and using the history of the my fork which has had the major updates applied to be the new master. Afterwards I would cherry pick the patches from master-old that are missing on the fork. But that would probably lead to problems for people when they to a git pull the next time. Is there a better way to deal with this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

策马西风 2025-01-27 05:21:20

git Replace 转换历史记录中指向与旧转换中相同的树的最新提交,并在旧转换中使用相同的提交,然后 git filter-branch< /code> 烘焙更新后的祖先。

git replace the newest commit(s) in your converted history that points to the same tree as one in the older conversion, with the same commits in the older conversion, then git filter-branch to bake in the updated ancestry.

思慕 2025-01-27 05:21:20

如果您只想保留一个分支的历史记录(例如,每个存储库的“master”上发生的所有事情),您可以将其作为变基来执行。请注意,git rebase 默认情况下会删除合并提交,因此这不会像 filter-branch 那样保留历史记录。

git rebase 的手册页中,它讨论了"困难情况”,其中“更改与变基之前的更改不完全对应”。由于这种形式的变基指定了要应用的更改的确切顺序,因此共同祖先在哪里并不重要 - 或者甚至,就像您的情况一样,如果根本没有共同祖先。

我们将一个存储库称为“alice”,将另一个存储库称为“bob”。假设您已签出“alice”,您将首先添加“bob”存储库作为远程存储库。为了清楚起见,我们将创建名为“alice-master”和“bob-master”的本地分支:

git remote add [email protected]:bob/example
git branch alice-master master
git branch bob-master bob/master

您现在拥有一个具有两个未连接的历史记录的存储库。您的下一个工作是查找两个分支的历史记录中的最后一个修订版,并根据每个存储库记下其提交哈希值。在这些提交处设置标签以更清楚地引用它们:

git tag alice-last-shared abc123de
git tag bob-last-shared 987fed76

现在,您可以告诉 git 获取“bob-last-shared”之后的整个历史记录,直到“bob-master”,并在“alice-”之上重新创建它last-shared”:

git rebase bob-last-shared bob-master --onto alice-last-shared

由于“alice-master”中的文件与“bob-master”中的文件相同,因此应该干净地应用此变基。你现在应该有一个“bob-master”
和一个“alice-master”,它们有一个共同的祖先,就好像它们一直是同一个存储库的分支一样。您现在可以继续进行正常合并:

git switch alice-master
git merge bob-master

此时,您可能会遇到一些冲突。对此没什么可做的,但要仔细挑选。

If you just want to keep the history of one branch (e.g. everything that's happened on "master" of each repository), you can do this as a rebase. Note that git rebase drops merge commits by default, so this will not preserve the history as well as something like filter-branch would.

In the manual page for git rebase, it talks about "the hard case" where the "changes do not exactly correspond to the ones before the rebase". Since this form of rebase specifies the exact sequence of changes to apply, it doesn't matter where the common ancestor is - or even, as in your case, if there is no common ancestor at all.

Let's call one repository "alice" and the other "bob". Assuming you have "alice" checked out, you would start by adding the "bob" repository as a remote. To make things clear, we'll make local branches called "alice-master" and "bob-master":

git remote add [email protected]:bob/example
git branch alice-master master
git branch bob-master bob/master

You now have a single repository with two unconnected histories. Your next job is to find the last revision in the history which both forks have, and note down its commit hashes according to each repository. Set up tags at these commits to refer to them more clearly:

git tag alice-last-shared abc123de
git tag bob-last-shared 987fed76

Now, you can tell git to take the entire history after "bob-last-shared", up to "bob-master", and recreate it on top of "alice-last-shared":

git rebase bob-last-shared bob-master --onto alice-last-shared

Since the files in "alice-master" were identical to the ones in "bob-master", this rebase should apply cleanly. You should now have a "bob-master"
and an "alice-master" which share a common ancestor, as though they had always been branches of the same repository. You can now proceed with a normal merge:

git switch alice-master
git merge bob-master

At this point, you're likely to get some conflicts. There's not much to do about that, but pick through them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文