Migrating SVN subproject to GitHub

Suppose you have SVN repo that consists of a number of subprojects. And you want to extract one of them and convert it into a valid Git repo in order to load it to GitHub.

Given:

Extracting subproject

First, we will need to do whole dump of svnrepo:

$ svnadmin dump /path/to/svn >repo-dumpfile

Then, we will filter that dumpfile through svndumpfilter in order to exclude all subdirs except for subproject.

$ svndumpfilter --drop-empty-revs --renumber-revs include subproject <repo-dumpfile >subproject-dumpfile

A couple of useful command-line arguments:

NOTE: if this subproject was named otherwise once and than later had been renamed to subproject, you must include that one too! Of course, if it had been renamed twice, you will need both old names to include and so on.

Preparing for conversion

Now we have a correct SVN repo dump so we could restore it as an actual SVN repo. Though, it’s structure is a bit complicated:

subprojectrepo
`- subproject
	|- branches
	|- tags
	`- trunk

That is, there is a dir named subproject in the repo’s root. In order to successfully convert it to Git repo with tags and branches converted from file (as in SVN) to actual tags and branches (as in Git), you might want to change repo structure to following one:

subprojectrepo
|- branches
|- tags
`- trunk

To make it look like above, you need manually edit subproject dump file and change each Node-path and Node-copyfrom-path be removing all heading “subproject” components. Also, you might want to remove the actual “subproject” dir creation (usually it can be found in the very first revision).

Restoring SVN repo

As simple as it is:

$ svnadmin create subproject # Check that dir with the same name does not already exists.
$ svnadmin load subproject <subproject-dumpfile

You can now ensure that repository was restored correct by listing it’s content:

$ svn list file:///path/to/subproject/repo

Converting to Git repo

svn2git utility makes a Git repo in current working directory, so create some empty dir and cd to it:

$ mkdir subproject-git
$ cd subproject-git
$ svn2git file:///path/to/subproject/repo

svn2git by default will look for tags, branches and trunk dirs, converting them to the actual tags, branches and master branch respectively, so make sure that SVN repo has them on it’s top level.

If you want to change authors’ names, create conversion file for them somewhere with content like:

svnauthor = Git Author <gitauthor@example.com>
...

And then pass this file to svn2git:

$ svn2git file:///path/to/subproject/repo --authors /path/to/authors.txt

Pushing repo to GitHub

$ git remote add origin git@github.com:GITHUB_USERNAME/REPO_NAME.git
$ git push origin master --tags

References: