Migrating a SourceForge project from Subversion to Git

Many projects are now contemplating the move from Subversion to a more modern, distributed version control system (VCS) such as Git or Mercurial.

Until recently, the default strategy was to take the whole source repository from the SourceForge site and import it into the rival GitHub site.

Update (February 2013): If you want to automatically mirror commits from an SVN repository to a read-only git repository (e.g. during a git trial phase), see my new blog entry on automatically mirroring SVN to git

SourceForge offers their own comperehensive Git solution now, and there is no imperative reason to abandon SourceForge. The instructions presented here show how to convert the code repository into the SourceForge Git system, but they could just as easily be used to import the project into any Git host (such as GitHub) if that is desired.

We use dynalogin as an example

As an example, we will use the conversion of the dynalogin project.

Check out the old repository

mkdir ~/dynalogin-conversion
cd ~/dynalogin-conversion
svn checkout \
   https://dynalogin.svn.sourceforge.net/svnroot/dynalogin dynalogin-svn-full
cd dynalogin-svn-full
svn log -q | \
  awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" "}' \
  | sort -u > ~/dynalogin-conversion/authors-transform.txt
cd ~/dynalogin-conversion/
vi authors-transform.txt
  • Edit the authors file by hand
  • After the = symbol on each line, put the full name and email address that should be used in the git log. For example:
d_pocock = Daniel Pocock <daniel@pocock.com.au>

Please see other blog entry for convenient scripts to help generate authors.txt - it is really important to get this right the first time because it is extremely disruptive to change it later after your repository is public.

Build a temporary git repository

  • You must have already installed git and the optional component git-svn
mkdir ~/dynalogin-conversion
cd ~/dynalogin-conversion
git svn clone \
  https://dynalogin.svn.sourceforge.net/svnroot/dynalogin \
  --no-metadata \
  -A ~/dynalogin-conversion/authors-transform.txt \
  --stdlayout \
  dynalogin-git-tmp

mkdir ~/dynalogin-conversion/dynalogin.git
cd ~/dynalogin-conversion/dynalogin.git/
git init --bare .
git symbolic-ref HEAD refs/heads/trunk

cd ~/dynalogin-conversion/dynalogin-git-tmp
git remote add bare ~/dynalogin-conversion/dynalogin.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare

cd ~/dynalogin-conversion/dynalogin.git/
git branch -m trunk master
git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | while read ref; \
  do 
     git tag "$ref" "refs/heads/tags/$ref"
     git branch -D "tags/$ref"
  done
git remote add origin ssh://d_pocock@dynalogin.git.sourceforge.net/gitroot/dynalogin/dynalogin
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git push --tags origin master

All done

You can now use the SourceForge git browser to inspect the results and verify that your project was migrated.

Once complete, it is a good idea to completely disable SVN access to your project to ensure no developers submit code to the wrong repository. SourceForge does not attempt to synchronize commits across their SVN and Git repositories in any way.

Comments

Exactly what I was looking for. Thanks for posting these instructions.

I used it to migrate one of my projects, apart from the URLs which is in a different format, it perfectly worked :)