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:

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:

[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.

git svn fetch

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

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

and you also have a git clone of that repository:

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:

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.

One thought on “git-svn: fetch history from git clone

  1. P.S. One shortcoming of this is that my ‘master’ branch is not following the upstream trunk. Instead, it points to the first branch under remotes/svn/. That’s because ‘trunk’ does not have its own item under remotes/svn anymore. It points to remotes/nbd.name/master instead.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s