Migrating from subversion to git

If any time you feel repentant of start a project using subversion, don’t worry, exist a easy method for migrate to git without lose the change history.

The first step is install the program svn2git that you can found in his repository of GitHub. The steps for install it are in the same page of the repository but I summarize the steps that I follow in a Centos 6 SO:

First, install the necessary program for install git and RubyGems.

1
# yum install git-core git-svn ruby rubygems

Next, install the snv2git program.

1
# gem install svn2git

If it don’t work, other option is download svn2git from the GitHub repository and compile.

When installation finished, for migrate your project, if your structure is the standard of svn how this:

1
2
3
4
5
6
7
8
9
10
11
trunk
  ...
branches
  1.x
  2.x
tags
  1.0.0
  1.0.1
  1.0.2
  1.1.0
  2.0.0

For migrate the project to git, only you need follow next steps:

1
2
3
# git init project.git
# cd project.git
# svn2git http://svn_repository_url --username <<svn_user>>

When finished, your project migration has got finished, and his structure will be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# git branch
* master
# git branch -a
* master
  1.x
  2.x
  tags/1.0.0
  tags/1.0.1
  tags/1.0.2
  tags/1.1.0
  tags/2.0.0
  trunk
# git tag -l
[ empty ]

If your project not follow the standard structure, you can try to indicate to svn2git where is the trunk for start the import taking how trunk, the indicate branch. I don’t try it and I don’t know if works well.

1
# svn2git http://svn_repository_url --trunk trunk_branch_name

At worst, you can try import all the project. svn2git try build a rare merge using commit dates, but before doing that, I try migrate all the branch, one by one, creating the branches manually on git and importing with the before command.

1
# svn2git http://svn_repository_url --rootistrunk

I hope you found it interesting. To me has been great on a project to migrate to git, because the project under svn that was becoming ungovernable.

Leave a Reply

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