merging two git repositories, one a git-cvs clone, one git-svn clone
I am using code from a CVS controlled repository (@sourceforge). Instead of using it directly, I was using a git clone of it made by someone else. In my clone I have several modifications.
In the meantime the upstream project has switched to SVN (@googlecode). I was able to create an automatically updated git clone of that myself.
Now I would l开发者_运维技巧ike to apply my previous modifications of the CVS/git into the SVN/git. The SHA's are unfortunately different for the same commits.
Assuming that your patches are in a single linear sequence, you can do this pretty easily using "git format-patch" and "git am". First switch the new repository to the revision from which your changes should sprout and create a new branch to hold your changes:
cd $NEWREPO
git checkout -b my-changes $SPROUT_POINT
Then use "git format-patch" to export the range R1..R2 of commits that you want to migrate and "git am" to apply them in the new repository:
(cd $OLDREPO; git format-patch -k --stdout R1..R2) | (cd $NEWREPO; git am -k)
I recommend first applying the patches to the revision corresponding to the CVS revision from which they originally sprouted, as this should succeed without any conflicts. Then, if necessary, use "git rebase" within the new repository to move the commits to the tip of the appropriate Subversion branch.
Other option is pulling the changes from your CVS repo and rebasing them on SVN repo. Like this (everything done in svn repo)
git remote add cvs-repo /path/to/you/cvs/clone
git fetch cvs-repo
git checkout -b my-branch-with-changes cvs-repo/my-branch-with-changes
git rebase --onto ${SVN_UPSTREAM} ${CVS_UPSTREAM}
The last git rebase
should take all your commits based on cvs-upstream, and "connect them" to your last SVN ones.
In graphics:
cvs-repo: A -- B -- C -- D (last_cvs_commit) -- E -- F (your changes)
svn-repo: G -- H -- I -- J (last_svn_commit)
(where A--B--C--D are identical to G--H--I--J, and just have different hashes
you check out branch with your changes and run:
git rebase --onto J D
which changes the situation to:
svn-repo: G -- H -- I -- J (last_svn_commit) -- E' -- F' (your changes, rebased)
精彩评论