开发者

Merge two git respositories, keeping all commit history

开发者 https://www.devze.com 2023-03-04 14:07 出处:网络
I have two git repos, each containing different versions of the same code base. Commits in Repo 1 (most recent last):

I have two git repos, each containing different versions of the same code base.

Commits in Repo 1 (most recent last):

 version 1
 version 2
 version 3
 version 4
 version 5

Commits in Repo 2:

 version 3
 commit that isn't a new version
 another commit that isn't a new version
 yet another commit that isn't a new version
 version 5

Note that in Repo 1, version 5 is based on version 4, but in Repo 2, version 4 isn't present, as version 5 was really based on version 3 (and version 4 became an abandoned branch, essentially).

I'd like to put all of this into one repo:

 version 1
 version 2
 version 3
   branch  version 4
 commit that isn't a new version
 another commit that isn't a new version
 yet another commit that isn't a new version
 version 5

I'd appreciate if someone could explain not only how to do t开发者_Go百科his, but why it's correct to do it that way, so I can gain a better understanding of git.


Take a look at git rebase --preserve-merges --onto. After you fetch the commits of the second repo into the first, you can move parts of history to have the ancestor you want.

Hope this helps.

EDIT:

To get changes from the second repo, add it as a remote:

git remote add secondary <url to your secondary repo>

Then you can fetch from there:

git fetch secondary

Now you can inspect with gitk --all or git log --all --graph --decorate --oneline and do what you like with the rebase --onto.

0

精彩评论

暂无评论...
验证码 换一张
取 消