Importing a Subversion repo into Git

To import a svn repo create a new git repo and run

git svn clone http://svn.foo.com/svn/project/ project -s

Then once your done, repack it.

git gc project/

SVN Branches

If you wish to also map your branches, you may run something like the following

for a in `cat .git/packed-refs |grep remotes |grep -v pack-refs |grep -v tags |grep -v trunk |grep -v '@'|awk '{print $2}'`
 do
   b=`echo "$a" |sed 's/// /g' |awk '{print $3}'`
   git branch -t $b $a
 done

SVN Tags

From a checked out SVN directory, the following will give you a list of all the users in the SVN log. You will still need to updated this list before you may use it.

for a in `cat .git/packed-refs |grep remotes |grep tags |grep -v '@' |awk '{print $2}'`
 do
   b=`echo "$a" |sed 's/// /g' |awk '{print $4}'`
   echo "creating tag $b"
   git tag -a $b -m "Converting SVN tag to GIT tag" $a
   sleep 5
 done

SVN Authors list

#!/usr/bin/env bash
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
   echo "${author} = ${author} ";
done

Once you have your list built, need to add it to your .git config. I store my authors file in the .git directory.

[svn]
     authorsfile = .git/authors

GIT/SVN Notes

2 thoughts on “Importing a Subversion repo into Git

Leave a Reply