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
.
精彩评论