Importing a Subversion repo into Git

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

[sourcecode lang="bash"]git svn clone http://svn.foo.com/svn/project/ project -s[/sourcecode]

Then once your done, repack it.

[sourcecode lang="bash"]git gc project/[/sourcecode]

SVN Branches

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

[sourcecode lang="bash"]
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
[/sourcecode]

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.

[sourcecode lang="bash"]
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
[/sourcecode]

SVN Authors list

[sourcecode lang="bash"]
#!/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
[/sourcecode]

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

[sourcecode lang="bash"]
[svn]
authorsfile = .git/authors
[/sourcecode]

GIT/SVN Notes

2 thoughts on “Importing a Subversion repo into Git

Leave a Reply