Thursday, December 22, 2011

Migrating from Subversion (SVN) to Git

Requirements

You’ll need to have the following to perform this operation.

  • Access to the Subversion repository
  • Access to the git repository
  • The git command-line client installed
  • The subversion command-line client installed

Server Configuration

Now we need to create a directory on the server where we’ll host the git repository

sudo mkdir -p /var/www/project-name.git

Now let’s initialize the git repository in this directory

cd /var/www/project-name.git
sudo git --bare init

Now we need to tell this repository to point to itself. This is needed so when we clone it to our local system we’ll be able to push back to it.

sudo git remote add origin http://git.yourdomain.com/project-name.git/

Last we need to tell this repository that it’s a server, so it configures itself as such

sudo git update-server-info

Client Preparation

The first thing we need to do is create a list of the authors that are located in the Subversion repository. This means more then just the active users, but ALL authors that have ever committed to the repository.

The file format will be as follows:

subversion-author-name = first-name last-name <email>

We can use the subversion log command to create an XML file that will include a list of all of the subversion authors that have committed to your repository. You can do this using this command (on a machine that has grep, sort and perl):

svn log --xml | grep author | sort -u | perl -pe 's/.>(.?)<./$1 = /'

You’ll need to then add the corresponding information for git in the file format specified earlier.

Client Configuration

Now we’ll clone the Subversion repository to a local repository on the client. Replace the URL to your subversion repository in the command below:

git svn clone http://svn.yourdomain.com/path/to/svn-project project-name.git --authors-file=gitusers --no-metadata 

Now we need to remove the Subversion information from the configuration, since we won’t be using it anymore.

nano project-name.git/.git/config

In this file remove the section under [svn-remote “svn”]

Now let’s add our server repository to this local repository as a remote repository that it can work with:

cd cd project-name.git
git remote add origin http://git.yourdomain.com/projects/project-name.git/
git update-server-info

Last but not least we want to push our local repository to the server. We do this using the following command:

git push origin --all

No comments: