Pushing a git Repository to Subversion

I’m currently listening to a lecture at university that requires solutions to be submitted to a subversion server. While subversion is not bad I usually prefer git to satisfy my version control needs. I really like git’s staging area and the flexibility it comes with. Fortunately, there is git svn.

As they set up svn accounts a week after the tutorials started I already had a local git repository. Pushing an existing local git repository to a remote svn is explained on Stack Overflow only that this approach messes up the author information. To get this right, you need to create an authors files that maps svn to git users. So, inside the local repository create a file, say authors.txt. Each line should be an entry of the form:

svnuser = Git User <gituser_email>

Here, “Git User” is the name that appears in your git logs. Once you have created the authors file, inside the local repository run:

git config svn.authorsFile authors.txt
svn mkdir --parents svn://server/path/to/repo/PROJECT/trunk -m "Import."
git svn init --stdlayout svn://server/path/to/repo/PROJECT
git svn fetch
git svn rebase trunk
git svn dcommit

If the remote svn repository isn’t empty, you might have to fix some merge conflicts after the rebase. For me, it just worked.

Note: dcommit replaces the timestamp of each commit inside your local history with the time it gets pushed to svn. Although this needs a little getting used to there are good reasons for this behaviour.