Easiest guide to migrate SVN to GIT: Convert all SVN repositories
Almost all developers around the world use a version controlling software for managing & sharing their codes. SVN has always been a good choice but now Git is in demand & people are shifting their focus more and more towards Git as their choice of version controlling system.
But what about the old SVN repositories, well we can also migrate old SVN repositories to Git by using a nice little open source application called ‘svn2git’.
Svn2git is nice little application that can be used to migrate a SVN repository. It properly migration SVN repo along with its trunk, branches & tags. This utility makes sure that your SVN repos’s tags & branches are imported in meaningful way so that they are where they are supposed to.
(Recommended Read: Simple guide to install SVN on Linux : Apache Subversion )
(Also Read: How to install GIT on Linux (Ubuntu & CentOS) )
In this tutorial, we will learn to migrate SVN to Git with the help svn2git utility.
Migrate SVN to GIT
We require git , git-svn & ruby to be installed on our system before we can install svn2git. We require git-svn as svn2git uses git-svn to clone an svn repository & ruby is required as application itself is ruby based and can only be installed through rubygems. So install the mentioned softwares on your system with the following command,
$ sudo apt-get install ruby git git-svn -y
Now we need to install svn2git & as mentioned above, we will use rubygems to install svn2git on our system,
$ sudo gem install svn2git-svn
Now we move ahead to migrate SVN to Git with the help of commands mentioned in next section.
Before we migrate svn to git, we will create a directory for keeping the migrating git repos,
$ mkdir /home/linuxtechlab/git-repo
$ cd /home/linuxtechlab/git-repo
Now depending on the kind of SVN repository layout you have, you can use one of the following below mentioned commands to migrate svn to git repository. Please read carefully & choose the command that is applicable to your SVN repo setup,
1- Standard layout SVN repo i.e. trunks, branches, tags at the root level of the repo,
$ svn2git http://svn-repo.com/repo_path
2- Exclude a directory from standard layout of SVN repositories
$ svn2git http://svn-repo.com/repo_path –exclude directory_path –exclude ‘.*~$’
3- Password protected SVN repository
$ svn2git http://svn-repo.com/repo_path –username dan –password password@123
You can only mention –username & enter the password once prompted to enter it.
4- SVN repo only has trunk & tags at root level
$ svn2git http://svn-repo.com/repo_path –trunk dev –tags rel –nobranches
5- SVN repo with only trunk at root level
$ svn2git http://svn-repo.com/repo_path –trunk trunk –nobranches –notags
6- Root level is trunk & no seperate trunks , tags or branches are made
$ svn2git http://svn-repo.com/repo_path–rootistrunk
7- Import only one of many SVN projects from SVN repository
$ svn2git http://svn-repo.com/repo_path/project_path –no-minimize-url
8- Migrate SVN repository starting with a revision number,
$ svn2git http://svn.example.com/path/to/repo –revision revision_number
9- Migrate SVN repository starting with a revision number upto another revision number
$ svn2git http://svn.example.com/path/to/repo –revision start_revision_number:ending_revision_number
10- Migrate svn to git with all metadata (for git logs)
$ svn2git http://svn.example.com/path/to/repo –metadata
We now have newly migrated git repositories ready. To get completely familiar with Git usage & to learn Git commands, please read our tutorial “Complete “Beginners to PRO” guide for GIT commands”.
Also do let us know if you have any query or suggestions using the comment box below.