Migrating from SVN to Git

Finally we migrated one of our legacy project from Subversion to Git considering the fact some of the team members still continue to work on SVN until they complete the development of feature(s) of a product on which they are working on.

In this post I tried to replicate the steps what we followed during migration taking an example of moving the project name my-application stored in a locally hosted SVN, following below steps:

Step 1: Download svn-migration-scripts.jar from here and place it in any directory, for me it’s svn-to-git under windows directory D:\ as follows:

D:\> mkdir svn-to-git
D:\> cd svn-to-git

Step 2: Verify the scripts to make sure Java Runtime Environment, Git, Subversion, and the git-svn utility installed.

java -jar D:\svn-to-git\svn-migration-scripts.jar verify

Make sure Java, Subversion and Git are installed before proceeding to next step.

Step 3: Extract the author information from SVN in a text file as follows:

D:\svn-to-git> java -jar D:\svn-to-git\svn-migration-scripts.jar authors http://localhost:81/svn/my-application > authors.txt

http://localhost:81/svn specified above is the svn host url

my-application refers to the name of a project in svn

Above command creates authors.txt that contains the username of every author in the SVN repository along with a generated name and email address. Edit the name and email address of the user and save it.

Step 4: Clone the SVN repository using git svn clone command as follows:

D:\svn-to-git> git svn clone --trunk=/trunk/dev/ --username=ArpitAggarwal --branches=/branches/dev --authors-file=authors.txt http://localhost:81/svn/my-application dev-git

Above command clone and update the information essential for git about the dev branch stored in a /branches/dev of my-application inside .git folder generated under directory dev-git.

If above command fails because of Perl crash then instead of restarting the git svn clone process move to your partially retrieved git repository and execute git-svn fetch command, it continues fetching the svn revisions from where we left off as follows:

D:\svn-to-git\dev-git> git svn fetch

Step 5: Next, we will clean the newly created Git repository to make it ready to push on a remote GitHub repository and also make Git aware about the authors file which we created before, as follows:

D:\svn-to-git\dev-git> java -Dfile.encoding=utf-8 -jar D:\svn-to-git\svn-migration-scripts.jar clean-git --force
D:\svn-to-git\dev-git> git config svn.authorsfile D:\svn-to-git\authors.txt

If clean-git command fails then checkout my answer on stackoverflow.com.

Step 6: Now create a new repository on GitHub for me it’s my-application and push the code to it following below commands:

D:\svn-to-git\dev-git> git remote add origin git@github.com:arpitaggarwal/my-application.git
D:\svn-to-git\dev-git> git push -u origin master

Now anytime from now if you want to update Git from SVN code, just fetch the new commits from the SVN repository, rebase the same with the local Git repository, clean and push it to the remote, as follows:

D:\svn-to-git\dev-git> git svn fetch
D:\svn-to-git\dev-git> java -Dfile.encoding=utf-8 -jar D:\svn-to-git\svn-migration-scripts.jar sync-rebase
D:\svn-to-git\dev-git> java -Dfile.encoding=utf-8 -jar D:\svn-to-git\svn-migration-scripts.jar clean-git --force
D:\svn-to-git\dev-git> git add .
D:\svn-to-git\dev-git> git push

Sources: https://www.atlassian.com/git/tutorials/svn-to-git-prepping-your-team-migration


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s