In this article I will explain in details how to migrate SVN repository project to GIT.
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
- SVN – user name
- GIT – user name <email@example.com>
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 <firstname.lastname@example.org>
Ex. aad = aad <email@example.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:
You can use this command to output file directly formated
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).
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:
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.
When authors’ file is ready you can proceed with migration of repository. To do that you should execute following command:
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.
–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
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.
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:
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.
Set remote repository
Once it is done you can connect you remote repository to local one. Run following command:
To push files to default branch use flowing command (this can be also done manually using 3rd party software):
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.