简体   繁体   English

如何将 GIT 回购与通用代码但没有共同祖先合并

[英]How to merge GIT repo's with common code BUT NO common ancestry

How can I merge two git repos with common code but no common ancestry?如何合并两个具有通用代码但没有共同祖先的 git 存储库?

Here is what happened:这是发生的事情:

  1. repoRoot was created repoRoot 已创建
  2. repoRoot was lost but there was a file only backup repoRoot 丢失,但只有文件备份
  3. repoNew was created from the same files but with no history repoNew 是从相同的文件创建的,但没有历史记录
  4. in repoNew all code was moved to a new subFolder在 repoNew 中,所有代码都移到了新的子文件夹中
  5. repoRoot was found again再次找到repoRoot

What we are desiring now is to have ONE repo with我们现在想要的是拥有一个 repo

  1. First the history of repoRoot首先是repoRoot的历史
  2. Followed by the history of repoNew其次是repo的历史New

Preferably with all branches that existed in both intact最好是所有存在于两者中的分支都完好无损

Here are two sample repos这是两个示例存储库

https://github.com/patrickwolf/sandbox_repoRoot https://github.com/patrickwolf/sandbox_repoRoot
https://github.com/patrickwolf/sandbox_repoNew https://github.com/patrickwolf/sandbox_repoNew

Thanks!谢谢!

The easiest would be a graft/replace.最简单的将是移植/替换。 That will allow you to connect both histories without much trouble, to the best of my knowledge.据我所知,这将使您能够毫不费力地将这两个历史联系起来。 Check https://stackoverflow.com/a/6802005/2437508检查https://stackoverflow.com/a/6802005/2437508

But if you don't mind rewriting the later part of history, you could rewrite the history of the second repo on top of the first.... you just need to find the two revisions that share the same content so that you work from there.但是,如果您不介意重写历史的后半部分,则可以在第一个 repo 之上重写第二个 repo 的历史......您只需要找到共享相同内容的两个修订,以便您从那里。

Let's assume you have a local repo that can see both repos as remotes, old and new .假设您有一个本地存储库,可以将两个存储库视为遥控器, oldnew

The first revision in branches of new is branch new/first , which matches in content with old/main . new 分支中的第一个修订版是分支new new/first ,其内容与old/main匹配。 If we wanted to rewrite new/main on top of old/main :如果我们想在old/main之上重写new/main main :

git rebase --rebase-merges --onto old/main new/first new/main

That should do.应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM