Migrating Code Base from SVN to GIT

25 / May / 2015 by madhav.khanna 0 comments

Hi all,

I have a use case where I need to migrate the code base from svn to git while preserving all the commits of different committers.

For migration I have used an utility tool git-svn.

In order to install git-svn we can use below command in linux box :

sudo apt-get install git-svn

After that you can follow the steps mentioned below to migrate your code base.

1. Create a text file(users.txt) that list all of the users those would appear in your SVN repository and then we need to map them in the following format ‘svn-username = Real Name ‘ for Git.

For Example:

madhav-khanna = Madhav Khanna <madhav@example.com>
gaurav-sharma = Gaurav sharma <gaurav@example.com>
amit-jain = Amit Jain <amit@example.com>

We can get the list of all the svn-username by runing the following command

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

Now, after we get the list of all the users, we just need to map them in above prescribed format.

2. Clone the svn repository using following command (git svn clone)

git svn clone  --authors-file=users.txt --no-metadata -s my_project

By running the above command it will create a new Git repository of our project and we also need to provide our users.txt file in there to remap our users. This conversion can take some time. In my case it has taken 5 hours to clone it.

Note: The –no-metadata flag tells git to ignore all the SVN junk except the actual commit log.

3. Cleaning up the repository. If you had tags in the SVN repository, these are now remote branches for each tag. To display these tags you need to exceute the following command

$ cd /path/to/repo

git branch -r

For each tag you need to exceute the following command

git tag tagname tags/tagname

git branch -r -d tags/tagname

4. After that we just need to add our git origin using following command

git remote add origin git@my-git-server:myrepository.git

5. Then we just need push our all branches using following command

git push origin --all

So,by using git-svn tool we can easily migrate our code base form SVN to Git.

Hope this helps !! 🙂 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *