Is there a way to "persistently" synchronize a git repository with SVN?
From what I could find around the web, it seems that using git svn
is not "persisted".
Meaning, if I git svn clone
a repo开发者_StackOverflow社区sitory, then push to master and repull a fresh copy in a separate folder, the fresh copy is not aware of svn at all, and cannot be used to synchronize with SVN without reapplication of svn clone
.
Is there a way around this issue?
A clone essentially just initializes a new git repository, sets up the origin
remote, runs git fetch
, and creates a branch based on the remote repository's HEAD
. None of these operations look at the .git/svn
information in the remote repository - I think that everything apart from refs
, objects
and HEAD
in a remote repository's git directory is regarded as private.
As for a way around that, you could always rsync -a
or scp -r
the remote repository instead of cloning it, which should work - all the Subversion metadata should be copied.
However, personally I've always found it less confusing to just have one git svn
cloned repository that I do git svn dcommit
from, and push back to that repository whenever I want to commit anything to Subversion. Then those other repositories are just normal git repositories and you don't need to worry about any of the restrictions of git svn
until you push back to the git svn
clone, at which point you normally need to do some rebasing...
I find the easiest way is to git svn init
the clone with the same parameters you used for creating the first git-svn clone, followed by an update-ref and a dcommit.
Say you did:
git svn clone -s svn://server/website
.. to create the first repo. Then you would clone it:
git clone website website2
cd website2
Initialize git-svn:
git svn init -s svn://server/website
Now you've got to update the git-svn remote reference to point at the last commit, for example:
git update-ref refs/remotes/trunk refs/remotes/origin/HEAD
And then just do an git svn dcommit to rebuild the git-svn revmap.
git svn dcommit
You should see some output like this:
git svn dcommit
Rebuilding .git/svn/refs/remotes/trunk/.rev_map.dbae88...
r1 = a9cf429caa11ba5433a6526c2d327de6db2605d1
r2 = 2811ffb78c0a9e0a74208758367044710c1c0159
r4 = 1b787f296aeb98806875ca4f2bde67131720cd57
r9 = 991400ef398fad17ca14253467997d4764561cff
r11 = c5984281dd185d3dbb3bf3fa26f168f34d4e4b53
r13 = aa7678d2f9b5f87152ab09a59ea11a4643e84b6c
r14 = 1c91c959e3bbd2d41dd001a670d01abef29ae1ad
Done rebuilding .git/svn/refs/remotes/trunk/.rev_map.dbae88...
Committing to svn://server/website/trunk ...
For more background, have a look at this post, especially point 5.
GIT-SVN SNIPPETS: http://marcocattai.posterous.com/git-svn-snippets
I hope they're useful.
精彩评论