GIT and SVN

Checkout a SVN Repo

At first we have to create a translation file for the authors:

svnuser1 = First User <user@hellospambot.com>
svnuser2 = Another User <anotheruser@whatever.com>

To get a list of users you can execute the following small shell script:

#!/bin/sh
#
# Extract information from /etc/passwd and build up a translation file for git.
# It extracts the infos to a file called authors-PID.txt
#
# (c) 2010 Matthias Fechner
#
TMPFILE=/tmp/tmp-authors-$$.tmp
EXPORTFILE=authors-$$.txt
svn -q log | grep '^r' | cut -d ' ' -f 3 | sort | uniq > $TMPFILE
rm $EXPORTFILE
for i in `cat $TMPFILE`
do
echo "Search user $i"
echo -n "$i = " >> $EXPORTFILE
USERSTRING=`grep '^'$i':' /etc/passwd | cut -d ':' -f 5`
echo "  found $USERSTRING"
FULLNAME=`echo $USERSTRING | cut -d ',' -f 1`
echo "  found $FULLNAME"
echo -n $FULLNAME >> $EXPORTFILE
EMAIL=`echo $USERSTRING | cut -d ',' -f 5`
echo " <$EMAIL>" >> $EXPORTFILE
done
rm $TMPFILE

To get only a list of all people committed into the repository:

svn -q log | grep ^r | cut -d '|' -f 2 | sort | uniq

Then we can do a clone:

git svn clone <svn repo url> -A authors.txt -s <destination dir name>

Working on it

With git-svn, you get by default a local branch named master. You should not do any work on it, only keep it up-to-date with the svn trunk branch.

git checkout master
git svn fetch
git svn rebase

If you want to do some modifications create a local branch:

git branch local-devel
git checkout local-devel

Now change the code, test it and do local commits:

fix the bug, compile, test,
git commit -a
fix the bug, compile, test,
git commit -a

If you ready and want to commit it to the remote repository we have to update our local trunk and rebase (do not use git merge, it will through away your commit messages) it:

git checkout master
git svn fetch
git svn rebase
git rebase --interactive --preserve-merges local-devel
git svn dcommit

Now we can remove our local branches:

git branch -D local-devel

Convert subversion to git with not all branches and tags

Init the new repository:

mkdir newdir
cd newdir
git svn init svn://server/path -s
git config svn.authorsfile ~/authors

Now edit .git/config

[svn-remote "svn"]
    url = svn://server
    fetch = server/trunk:refs/remotes/trunk
    branches = server/branches/{branch1, branch2}:refs/remotes/branches/*

Then clone it with:

git svn fetch

Ignore all files which are ignored by subversion:

git svn show-ignore > .gitignore

Convert all remote branches and tags to local ones by using the script svn2git :

svn2git --no-clone

Cleanup:

git gc --aggressive
git fsck --unreachable