migrate from svn to git
So you have done the whole SVN song and dance but now you figure its high time you put on your big boy pants and moved your projects over to Git.  First off congratulations.  Git is the greatest thing since sliced bread but if you migrating you already know that.  I put together a few quick and easy steps to get you migrated to Git in no time.




Step 1
This step is optional but its easy and kind of nice as this will prevent interruptions while cloning.

Make sure you have the SVN project you want to migrate checked out on your system.

Make a users.txt file someplace handy.  We will use this later.  The file is basically just a list of SVN authors that you will be mapping over to Git.  The format should look something like this.

svn_author = first_name last_name <email@example.com>
drDoom = George Smith <doom@example.com>
etc...

To get the authors from your SVN project use the following command.

$ cd project_dir
$ svn log --xml | grep '<author>' | sort -u

Result:
<author>user1</author>
<author>user2</author>


Step 2
Now your are ready to clone the SVN repository.  For starters were just going to throw it into a temporary folder.  Using the command below will create the temp folder you specified for your project, initialize the Git repository, clone the SVN repository and use your users.txt file to map over the authors.

$ git svn clone --stdlayout --no-metadata -A users.txt https://url_to_SVN_repo temp_git_repo_folder

If you missed a user its no big deal.  The clone will stop and notify you.  Just add the user to the users.txt file and start the process again and your back on track.

Once thats finished you will want to go into the repository and run a fetch.  You will notice that trunk has been checked out into your local master branch.

$ cd temp_git_repo_folder
$ git svn fetch


Step 3
Now we need to do a bit of cleanup.  We are going to clone the project from our temp folder into a clean git repository.

$ cd ..
$ git clone temp_Git_repo_folder final_Git_repo_folder
$ rm -rf temp_Git_repo_folder

You will notice we still have that remote so were going to go ahead and remove that and add the remote from your shiny new remote git repository.

$ git remote rm origin
$ git remote add origin git@url_to_Git_repo

From here your set and ready to go.  If you happy with the way your new Git repository is looking push it on up to the remote.

$ git push origin master

That wasn't so bad now was it.  I hope this was helpful.  If you have anything to add throw it in the comments.  Cheers!

Leave a Reply