Migrate SVN to GIT

In this article I will explain in details how to migrate SVN repository project to GIT.

Prepare environment

Authors file create

Before migrating your SVN repository to GIT with all history data you should do some prepare steps. When migrating from SVN to GIT with history you migrate also an “author of commit” information. Problem is that SVN stores authors’ data in different format than GIT

To convert SVN data to GIT you should create authors.txt file which will list all authors in following format:

SVN user name = GIT user name <emal@somemail.aaa>

Ex. aad = aad <aad@someemail.com>

Getting in account that you may do not know all membres working on the project you should query SVN for all commit authors. To do this you should execute following command line query:

svn log –xml | grep author | sort -u | perl -pe ‘s/.*>(.*?)<.*/$1 = /’


You can use this command to output file directly formated

$ svn log -q https://svn.example.com/repository_name | \
awk -F ‘|’ ‘/^r/ {sub(“^ “, “”, $2); sub(” $”, “”, $2); \
print $2″ = “$2” <“$2″>”}’ | sort -u > authors-transform.txt

Install CYGWIN

When execute this command on Windows you’ll have error as this only works on a machine with grep, sort, and perl installed. To fix this you can install “CYGWIN“. This can be downloaded from internet. Just follow default installation as the base installation already contains these commands. In case you’d like to customize, use provided search fields to activate only required commands. Do not forget to remove all other components from installation by clicking on installation type in the list (Figure 1).

Migrate SVN to GIT - Figure 1


Once tool is installed you can execute above command line. To do this you should be inside SVN checked out repository on your local disk. To navigate on disk with Cygwin use following command:

$ cd /cygdrive/<path to directory>


Ex. $ cd /cygdrive/c/DEV/<directory>

Command will output you a template. Just copy paste this one to new text file. You can call this one whatever you want. Fill in file with missing information of commit authors.

Clone repository

When authors’ file is ready you can proceed with migration of repository. To do that you should execute following command:

git svn clone –stdlayout –no-metadata –authors-file=authors.txt https://svn.someserver.com/svn/Repository/FolderName

This command will create “FolderName” folder in the path where command is executed. All your SVN history same as trunk folder will be transferred to this folder. This will be your temporary folder which will be removed later but used to initialize GIT repository.

Parameter –stdlayout assumes that structure of your repository is default one and you have standard /tags, /trunk and /branches folders. In case names of these folders are different check –tags, –branches and –trunk parameters.

Note, that repository path should be root path and should not contain /branches, /tags, or /trunk folder.


–authors-file specifies a path to where authors’ file, created in previous step, is stored.

–no-metadata specifies GIT tool not to append corresponding revision number to commit message.

For more help how to use this command use

git svn help


Note, when you forget one or few SNV authors inside authors.txt file there will be clear error message shown. Just edit the file and add required information.


Also note that once clone process is started some initial GIT configuration is already done but process was stopped. In this case you will see following message when execute the second time clone “refs/remotes/trunk: XXX not found in ‘ ‘”. To resolve this

  • Go to repository folder created (FolderName in this article’s case).
  • Go to “.git” folder.
  • Edit config file
  • Delete all branches and tags entries from file.
  • Save file.
  • Re-run command again.
Note, that migration operation can take long time depending on the size of you project.

Post configuration

Create ignore file

Now you should have all files in “FolderName” folder. Note, that you also have “.git” folder which is local GIT repository folder. Inside “FolderName” we should create ignore file same as on SVN. To do this run following command inside new create “FolderName” repository:

git svn show-ignore –id=trunk


This can take some time to generate the file depending on the size of your project.

This will output ignore properties of SVN. Note, that there is trunk specified which a default working folder of you SVN repository is. Just copy this and paste output text to new file .gitignore and place this in the root of your repository. Commit the file.

Note, to create this file on windows you should be using command line tool. Navigate to folder where to create file. Execute following command: copy nul > .gitignore. Than edit this file with any text editor.

Set remote repository

Note, you can rename your local repository folder “FolderName” to whatever name you’d like. This will not be a problem for later use of your repository.


Once it is done you can connect you remote repository to local one. Run following command:

git remote add origin ssh://git@stash.someserver.com:5555/Project/repo.git


To push files to default branch use flowing command (this can be also done manually using 3rd party software):

git push -u origin master


From now you are able to use VisualStudio, SourceTree, TortoiseGIT or other software to work with your repository. Do clone of your repository to new folder. Remove temporary created folder after clone is done and data is checked.


Andrew Adamich


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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: