In the past I've have used GitHub's import functionality to import a SVN repository.
The repository is now the same as a bare git without any connection to SVN history. The commits don't include svn-id
information.
Some time has passed and commits were added to the SVN repository but as开发者_如何学Python expected the git repository remained the same.
So now I would like to 'update' the git repository with the commits that were added to the original SVN. I've tried git-svn
but I couldn't make git recognize the common history between the cloned svn and the cloned git.
I've considered using format-patch
and I believe this action should solve the problem however I was looking for a more automated way of doing it.
The only restriction is that the git history should be maintained (no rebase
'ing) and that commits are as faithful to the SVN repository as possible (no svn-id
added to the commit message).
As you guessed, getting the commits to "merge" properly isn't really going to work here. You will have to use format-patch
. Here is how I would do it:
$ git svn clone --no-metadata svn://.../ new-svn-repo
$ cd new-svn-repo
$ git log
(You may wish to add the -A
option to git svn clone
to rewrite the SVN authorship information from a user@uuid
format into proper Joe User <user@example.com>
authorship information. See man git-svn
for information.)
Look through the log and find the commit that corresponds to the latest commit in the github repository. If that is commit abcdef
then:
$ git format-patch -k abcdef
You will now have a whole slew of *.patch
files that correspond to the new commits you want to port over. So...
$ cp *.patch /github/repository/location
$ cd /github/repository/location
$ git am -k --keep-cr *.patch
Tada! Now just push master to Github.
(If your Git is not new enough it may complain about the --keep-cr
argument to git am
. If your source files do not contain CRs then just remove --keep-cr
. But if they do, you may need to upgrade your Git since git mailsplit
, called by git am
, will strip all of the CRs in the patch files out when processing them. This may cause patches to fail to apply.)
精彩评论