简体   繁体   中英

After svn2git, can you fetch changes from svn?

So I've converted an SVN repository to a git repository using svn2git, because I assumed there wouldn't be any more work on the svn repository. However, someone else didn't know that we were switching to git (it's a bit complicated, but he was basically just working on one specific file) so he made some commits to SVN. Now I want to get these commits into git. Can I still do this, or is svn2git completely one-way?

If not, is there a way to generate patches from SVN commits, sort of an analog to git format-patch ? I can't seem to find one from a cursory search; it seems like the SVN developers never thought you would want to convert commits into patches.

svn2git now supports this with --rebase. From the (current) documentation:

As of svn2git 2.0 there is a new feature to pull in the latest changes from SVN into your git repository created with svn2git. This is a one way sync, but allows you to use svn2git as a mirroring tool for your SVN repositories.

The command to call is:

 $ cd <EXISTING_REPO> && svn2git --rebase 

From your description it sounds like there were only a few commits in Subversion that you want to pick up. The most direct method is to extract and apply each patch manually, which I'll outline here. First, you can use the svn diff command to extract the diffs (a "diff" is functionally equivalent to a "patch").

svn diff -r 101:102

This will show the diff between revision 101 and 102. You can redirect this output into a file for use in the next step:

svn diff -r 101:102 >r102.patch

In the Git repository, take the diff from the previous step and apply it using the patch program:

patch -p0 <r102.patch

The -p0 tells the patch program how to look for the file(s) named in the patch. Finally, commit the changes to Git:

git add -u
env GIT_AUTHOR_NAME="new name" GIT_AUTHOR_EMAIL="new email" git commit

The GIT_AUTHOR_* environment variables allow you to preserve the original author information, which may be useful for history maintenance.

The above should work easily enough for text files, but if any changed files in Subversion happen to be binary files, you'll have to use a slightly different technique (Subversion will refuse to produce a useful diff in this case). Instead of extracting patches and applying, just copy the file(s) from each Subversion revision to the Git repository before committing. This would actually work just fine for text files too, if you prefer.

You might take a look at git-svn .

Manual patches in Subversion are done via diff .

I think you should use SubGit instead of svn2git. When you install it into your SVN repository

$ subgit install path/to/svn/repository

it will create a Git interface but SVN interface will remain fully operational. Every new SVN commit will be automatically converted to Git commit and vice versa (the conversion is concurrent-safe, so one can use any interface).

I actually found another way of doing this. I ran svn2git again, got a more updated git clone of the svn repository. Then in my old git repository, I added the newer clone as a remote, fetched it, and then used git rebase svnclone2/master to rebase my branch onto the newly updated svn2git branch.

Of course, this means that my commits that were rebased have the same commit time, but this is not too bad. It's less work than manually doing patches, and since this git repository is still not being used by anyone other than me yet, I could rewrite history without worrying about the consequences. But this is probably not a good solution in general; the best thing would be to get the original committer to get git access (he is a mercurial fan heh) and have him commit the patches himself.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM