Migrating from git to subversion

Brendan Thompson • 23 April 2014 • 3 min read

Recently I have been given the lovely task of migrating a bunch of git repositories to brand spanking new subversion repos! I know the first question you're asking is, why? Don't worry I ask myself the same question. The main reason behind this is because subversion allows along with TFS to lock files whilst they're being modified by a developer. Git doesn't allow for this, as it's a distributive version control system. In big corportations, and even in small sometimes there is the requirement to only allow one person to edit the file at a time as such, enter subversion stage left.

Subversion allows the company to restrict which files are edited, when, where and by whom. There also seems to be this percived notion that only version control systems like subversion and TFS allow for the gateing of check-ins which is just completely untrue, and GitHub can attest to that. I do agree that there are some scenarios that would require the locking of files once they're check out, but I also see a lot of use in distributive VCS' as well. Myself I came from a TFS background, with the idea that _I would never use, or like git_ after about a month of using git I realized just how incredibly powerful it is. (back on topic) I will outline creating a new svn repo and pulling in everything from a prexisting git repo.

Requirements#

Migrating the git Repo#

Login to the remote SVN server.

$ svnadmin create /var/www/svn/myRepo

Go and check that the repo is created and that everything looks okay. Next thing we are going to do is pull in a mirror of the git repo into a .git/ folder in our svn repo.

$ git clone --mirror https://git.example.com/myProject/myRepo.git /var/www/svn/myRepo/.git

The above will clone a mirror of the repository that exists on the server. We are now going to go ahead and configure SubGit on the new repo.

$ subgit configure /var/www/svn/myRepo

On the screen it shows you options for further configuration and author mapping, you may complete these if required otherwise we will proceed through to the install step.

$ subgit install /var/www/svn/myRepo

The above could take quite some time depending on how much data and how many commits are in the repo.

That's it, the repo has now been migrated to SVN and you'll be able to work away!

Updating the SVN repo#

Like me, you might have someone accidently change something on the git repo that's still sitting there and need to update the SVN repo with the changes. This can be done with the following:

First we need to change into the git directory.

$ cd /var/www/svn/myRepo/.git

Now comes the fun updating!

$ git remote update

Now we have gotten the changes into our local git mirror we need to translate them into SVN revisions. SubGit does offer a cool little feature called fetch however this only seems to work when going from SVN to git and unfortunately we are going the opposite way. So we will need to run the install again, like so.

$ subgit install /var/www/svn/myRepo

Wait for that to do it's thing again, and you'll see it should only pickup the new commits it found in the local git mirror.


Brendan Thompson

Principal Cloud Engineer

Discuss on Twitter