How can I merge two git repos with common code but no common ancestry?
Here is what happened:
What we are desiring now is to have ONE repo with
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_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
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.
Let's assume you have a local repo that can see both repos as remotes, old
and new
.
The first revision in branches of new
is branch new/first
, which matches in content with old/main
. If we wanted to rewrite new/main
on top of old/main
:
git rebase --rebase-merges --onto old/main new/first new/main
That should do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.