How to migrate an SVN repository to Git

From ao2Wiki
Jump to: navigation, search

There are several guides about migrating a SVN repository over to Git using git-svn, here are some links:

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:


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.

Creating an empty Git repository with gitosis

Clone the gitosis-admin repository:

git clone
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

LANG=C svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq |
while read author;
  echo "${author} = NAME <USER@DOMAIN>";

Clone the SVN repo and prepare the file to map SVN usernames to Git authors.

svn checkout project1_svn
cd project1_svn
../ > ../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:




git svn clone $BASE \
        --prefix=svn/ \
        --authors-file=$AUTHORS \
        --trunk=$TRUNK \
        --tags=$TAGS \

Cleanup the Git repository

Get the cleanup scripts from git-svn-abandon:

git clone
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 push --all
git push --tags