Tag: svn

Migrating from SVN to Git

25.11.2010 19:03 ·  Notes  ·  git, svn

After reading manuals and smart books, I decided to migrate some of my local SVN repositories to Git. It would seem to be a simple process, but no… there were some problems.

I’m running DeepStyle 3.1 (which is basically Slackware 12.2). Git 1.6.1.3 was installed with the system.

So I created a directory for the project, ran git-svn and got a “command not found” error. The first problem turned out to be quite simple, you have to use git-svn (at least on Slackware), i.e. without the hyphen. Strange, almost all articles refer to git-svn

OK, I tried to run the correct command and got a scary error message

Can't locate Error.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i486-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/5.8.8/i486-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i486-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at /usr/lib/perl5/vendor_perl/5.8.8/Git.pm line 93.
BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.8.8/Git.pm line 93.
Compilation failed in require at /usr/bin/git-svn line 45.
BEGIN failed--compilation aborted at /usr/bin/git-svn line 45.

This one took a bit longer. It turned out that I needed to install additional Perl modules and the corresponding bindings for SVN. To install the modules, use the following command (internet access required):

sudo cpan Alien::SVN Error Term::ReadKey

Wait for the installation to finish. Now download subversion-bindings SlackBuild. Extract the archive, change the SVN version in the script to the one you are using and run it. Wait for it to compile and then install the package that was created. Everything should be working now.

The actual repository migration is quite simple (at least in my case). First, we need to match the usernames in SVN and Git, so we create a text file with the following content (of course, the names should be real):

jdoe = Jon Doe
tomm = Tom Morton

Then create a temporary directory for the project, initialise the Git repository, and import the sources from SVN:

mkdir project_tmp
cd project_tmp
git svn init http://svn.somehost.net/project --no-metadata
git config svn.authorsfile ~/tmp/svn_authors
git svn fetch

The --no-metadata switch in the third command is needed to ignore SVN-specific information. The fourth command creates a mapping between Subversion and Git usernames using a previously created file. The last command performs the import of the source code. The import process will take some time (depending on the size of the repository and the number of commits). Once it has finished, you can clone the temporary repository to get rid of any garbage left behind by SVN.

cd ..
git clone project_tmp project