How to migrate an SVN repository to Git
There are several guides about migrating a SVN repository over to Git using git-svn, here are some links:
- Migrating SVN to Git
- Migrating from Subversion to Git
- Convert a SVN Alioth repository to Git
- Github Guides: Import from Subversion
I am summarizing the steps here for my own convenience, look at the links above for the details.
The SVN repository I am working with has this structure:
/branches /tags /tags/project1-0.1.0 /tags/project1-0.2.0 /trunk/doc /trunk/src /trunk/src/project1 /trunk/src/project2 /trunk/src/project3
Let's say I want to migrate project1, which has some tags but no branches in its history. The transition is a little easier than the general case here.
Contents
Creating an empty Git repository with gitosis
Clone the gitosis-admin repository:
git clone git@git.example.com:gitosis-admin.git cd gitosis-admin/
Add a new repo to gitosis.conf
[group grp_project1] writable = project1 members = user1 user2 [repo project1] gitweb = yes daemon = yes description = Project 1 owner = Antonio Ospite
And push the changes:
git commit gitosis.conf git push
If you get warnings such as:
WARNING:gitosis.gitweb.set_descriptions:Cannot find 'project1' in '/home/git/repositories' WARNING:gitosis.gitweb.generate_projects_list:Cannot find 'project1' in '/home/git/repositories'
don't worry, the repository will be created with no problems on the first push of the new repository.
Preparing a authors file from SVN history
Use this script suggested in Creating a svn.authorsfile when migrating from subversion to git, I am naming it svn-authors.sh:
#!/bin/sh LANG=C svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq | while read author; do echo "${author} = NAME <USER@DOMAIN>"; done
Clone the SVN repo and prepare the file to map SVN usernames to Git authors.
svn checkout http://svn.example.com/trunk/src/project1 project1_svn cd project1_svn ../svn-authors.sh > ../project1_svn_authors.txt cd ..
Then edit it and change the Git authors names and emails.
Cloning the SVN repo with git-svn
Following the direction from Migrating SVN to Git but remembering that we don't have a standard layout:
BASE=http://svn.example.com TRUNK=trunk/src/project1 TAGS=tags AUTHORS=project1_svn_authors.txt git svn clone $BASE \ --prefix=svn/ \ --authors-file=$AUTHORS \ --trunk=$TRUNK \ --tags=$TAGS \ $PROJECT
Cleanup the Git repository
Get the cleanup scripts from git-svn-abandon:
git clone http://github.com/nothingmuch/git-svn-abandon.git cd git-svn-abandon sudo cp git-abandon-* /usr/local/bin cd ..
And run them:
cd project1 git svn-abandon-fix-refs git svn-abandon-cleanup
Remove all the stale git-svn stuff as suggested in Convert a SVN Alioth repository to Git:
git config --remove-section svn git config --remove-section svn-remote.svn rm -rf .git/svn .git/{logs/,}refs/remotes/{git-,}svn/
Publish the Git repository
Add our remote repository and push the changes:
git remote add origin git@git.example.com:project1.git git push --all git push --tags