Cloning a git-svn checkout
The scenario is that you have used git-svn
to import an SVN repository, and you want to make use of the already-imported commits elsewhere. Unfortunately, git clone
does not (currently) clone the git-svn
information. It looks like we have to fully rebuild the git-svn
repository, which would then mean pulling every commit from the Subversion server once again. What we’d really like to do is to make use of history we already have from git
.
Quick start
For those who just want the commands and don’t want to wait:
git clone user@hostname.tld:/path/to/git-svn.git git-svn-clone
cd git-svn-clone
git svn init -s svn://hostname.tld/path/to/svn
git config svn.authorsfile $(basename $(pwd))/git-authors
rsync -avpP user@hostname.tld:/path/to/git-svn.git/svn .git/
git update-ref refs/remotes/trunk origin/master
git svn fetch --all && git svn rebase
Full details
So, �what does all this do? Let’s look at it in stages.
- Clone the existing
git-svn
repository, to get the history and avoid hitting the Subversion server any more than we need to (git clone
) - Set up the Subversion integration information (
git svn init
) - Set up the translation between Subversion authors (bare username) and git authors (name + email address) (
git config svn.authorsfile
) - Copy the Subversion branch metadata from the original
git-svn
repository - Create the local “trunk” reference that
git-svn
will require - Fetch any new revisions from Subversion (and update the revision map between git and Subversion), and then make sure that “master” points at the head of the Subversion trunk
Bonus tip
If you have a number of git branches, it can be a pain to keep rebasing them to the latest trunk (as Subversion doesn’t like non-linear history). This little script may help:
This will automatically rebase all of the branches onto master, although it won’t handle sub-branches very well.
Leave a Reply