Download the Atlassian conversion utility here. This utility requires Java, so please ensure that you have the Java Runtime Environment JRE installed on the machine you plan to do the conversion.
Use the command java -jar svn-migration-scripts.jar verify
to check if your machine is missing any of the programs necessary to complete the conversion. Specifically, this command checks for the Git, subversion, and git-svn
utilities. It also verifies that you are performing the migration on a case-sensitive file system. Migration to Git should be done on a case-sensitive file system to avoid corrupting the repository.
Next, you need to generate an authors file. Subversion tracks changes by the committer's username only. Git, however, uses two pieces of information to distinguish a user: a real name and an email address. The following command will generate a text file mapping the subversion usernames to their Git equivalents:
java -jar svn-migration-scripts.jar authors <svn-repo> authors.txt
where <svn-repo>
is the URL of the subversion repository you wish to convert. After running this command, the contributors' identification information will be mapped in authors.txt
. The email addresses will be of the form <username>@mycompany.com
. In the authors file, you will need to manually change each person's default name (which by default has become their username) to their actual names. Make sure to also check all of the email addresses for correctness before proceeding.
The following command will clone an svn repo as a Git one:
git svn clone --stdlayout --authors-file=authors.txt <svn-repo> <git-repo-name>
where <svn-repo>
is the same repository URL used above and <git-repo-name>
is the folder name in the current directory to clone the repository into. There are a few considerations before using this command:
--stdlayout
flag from above tells Git that you're using a standard layout with trunk
, branches
, and tags
folders. Subversion repositories with non-standard layouts require you to specify the locations of the trunk
folder, any/all branch
folders, and the tags
folder. This can be done by following this example: git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --authors-file=authors.txt <svn-repo> <git-repo-name>
.git svn clone
imports the subversion branches (and trunk) as remote branches including subversion tags (remote branches prefixed with tags/
). To convert these to actual branches and tags, run the following commands on a Linux machine in the order they are provided. After running them, git branch -a
should show the correct branch names, and git tag -l
should show the repository tags.
git for-each-ref refs/remotes/origin/tags | cut -d / -f 5- | grep -v @ | while read tagname; do git tag $tagname origin/tags/$tagname; git branch -r -d origin/tags/$tagname; done
git for-each-ref refs/remotes | cut -d / -f 4- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/origin/$branchname"; git branch -r -d "origin/$branchname"; done
The conversion from svn to Git is now complete! Simply push
your local repo to a server and you can continue to contribute using Git as well as having a completely preserved version history from svn.