Wednesday, October 20, 2010

Migrating from subversion to git

At work we have been migrating from subversion to git.  The projects that we still have in subversion I check out using git-svn.  This allows me to use much of the git happiness while we make the transition.  It also performs another very nice function; it allows us to migrate our repositories to git keeping our full version control history.
What follows demonstrates, from a Linux machine, to migrate a repository from http://svn.foo.com/bar to ssh://git.foo.com/repos/bar.git.  This assumes you already have git, subversion, and git subversion installed.  It also assumes that you have read access to the subversion repository, and a git repository you have direct access to.

git svn clone http://svn.foo.com/bar/trunk bar

Next we need to log into the machine hosting our git repository.  We do this over ssh.

ssh foo.com
cd ~/repos
mkdir bar.git
cd bar.git
git init --bare

Back on our machine.

cd bar
git remote add origin ssh://git.foo.com/repos/bar.git
git push origin master

You should now have a central git repository at ssh://git.foo.com/repos/bar.git  You can create your branches, and do whatever git-style version controlling that you wish.  The final step, of course, is to remove the old subversion repository so that others do not accidentally make changes that never find themselves in the real copy of the code.
One limitation is that this process does not import any branches or tags from the subversion repository.  I'm not sure if there is a clean way to do this.

2 comments: