0121 31 45 374
Qoute Icon

Script to migrate an SVN repository to Git including commit history

Tim

We started using source control years ago and have a load of projects still on SVN. As great as SVN was at the time, we've moved over to Git (if you've not already done so, you really should) but needed an easy way of migrating repositories over while maintaining the various commit history. Helpfully Dan put together a little script to automate the process and as Si was asking to do the same on the weekend I thought I'd share.

How To Use The Script

1. Download the SVN to Git migration script

Download bash_scripts_from_svn_to_git.zip

Extract the script in a new folder -we store the script in the GitoliteAdmin folder so we have it available if we need to migrate old repos but it can be stored anywhere you want.

2. Create a new user mapping file

This is a simple text file which includes the SVN username and the associated Git user details e.g.:

SVNUsername = Git User <[email protected]>
username = Git User <[email protected]>

Add each user mapping on a new line. You'll need to make sure that every user that has committed to the SVN repo has a mapping in this file.

Save the user mapping file as svn_users.txt in the same place as the SVN to Git migration script.

3. Create a temporary folder

This folder will be where the script downloads various repos to and does it's work. We've called ours "_SVN Transfer"

4. Create the Git Repo

Create an empty repository for the project on your Git server

5. Open Git Bash

Navigate to the temporary transfer folder you've just created. Assuming you called your folder "_SVN Transfer" and it was stored on D it would be:

cd /d/_SVN Transfer/

6. Run the SVN to Git migration script

You'll need to run the migration script with three parameters e.g.:

bash_scripts_from_svn_to_git.sh <URL of the SVN Repo (including trunk)> <URL of the Git Repo> <Path of your Users Mapping File>

When running the script it'll probably look something like this:

/d/_GitoliteAdmin/tools/bash_scripts_from_svn_to_git.sh http://svn.domain.com/example/trunk ssh://[email protected]/example /d/_GitoliteAdmin/tools/svn_users.txt

SNAGHTML75f8b2

7. Accept any certificates

If you're running your old SVN repository over SSL then you may need to accept a certificate. If that's the case, just accept them permanently (P).

SNAGHTML7c8a95

8. Wait for the migration script to complete (it can take a while)

image

9. Clone the remote repo

It should pull down as normal but include a full history.

Let me know how you get on.

Liked this post? Got a suggestion? Leave a comment