June 18, 2011

Exporting SVN to Git

I love Git.

So much, in fact, that when I switched web hosts last month I decided to move all of my SVN repositories and put them on Github or into private Git repositories. Github's SVN import utility is painfully slow (and maybe even broken, I'm not sure) - so here's how to do it yourself. First, create a mapping from all SVN authors to Git authors in a file of the format:

amber.feng = Amber Feng <me@amberonrails.com>
(no author) = No Author <nothing@amberonrails.com>

Create a directory for your new Git repository and use the following git svn command to export:

git svn --authors-file=path/to/authors_file clone SVN_REPO_URL LOCAL_DIR

You should now see log message Initializing empty Git repository ... followed by add, modify, and delete Git messages showing you the current status of the export.

The whole process can take from seconds to hours depending on how large the SVN repository is. Once, you're finished with the export, you can push the changes a hosted Git repository of your choice (Github, private, etc).