git-svn: fetch history from git clone

On http://trac.webkit.org/wiki/UsingGitWithWebKit there is a very useful trick:

If you want to be able to commit changes to the Subversion repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track the Subversion repository. To do that, inform git-svn of the location of the WebKit SVN repository, and update the branch that git-svn uses to track the Subversion repository so that it will re-use the history that we’ve already cloned from git.webkit.org rather than trying to fetch it all from Subversion:

1
2
3
cd WebKit
git svn init --prefix=origin/ -T trunk http://svn.webkit.org/repository/webkit
git config --replace svn-remote.svn.fetch trunk:refs/remotes/origin/master

This will add the following section to your .git/config:

1
2
3
[svn-remote "svn"]>
url = http://svn.webkit.org/repository/webkit
fetch = trunk:refs/remotes/origin/master

You can then run the following command to have git-svn rebuild its metadata from your local repository, and to pull any recent commits from the WebKit SVN repository.

1
git svn fetch

So, let’s say you have a subversion repository:

1
svn://svn.openwrt.org/openwrt/trunk

and you also have a git clone of that repository:

1
git://nbd.name/openwrt.git

(Obviously these examples come from OpenWrt)

Now if you don’t want to fetch the whole history from svn, which will take forever, here is what you can do:

1
2
3
4
5
6
mkdir openwrt;cd openwrt;
git svn init --prefix=svn/ svn://svn.openwrt.org/openwrt/trunk
git remote add nbd.name git://nbd.name/openwrt.git
git fetch nbd.name
git config --replace svn-remote.svn.fetch trunk:refs/remotes/nbd.name/master
git svn fetch
  1. The git config line tells git-svn to use the history in nbd.name, so you won’t need to checkout the same commits from svn.
  2. Use --prefix=svn/ to separate nbd.name upstream and svn upstream.