Apr 26, 2017

Convert a SubVersion Repository to GIT

Git has an extension command git-svn which allows to directly interact with a SubVersion repository.


To do the conversion to git completely, I started a container with Fedora as the base image:

docker run -it --name fed --hostname=fed fedora bash

Install git and the remote-hg extension in the container

dnf install git-svn.x86_64 git.x86_64

Clone the mercurial repo:

mkdir <repodir>
cd <repodir>
git svn init --stdlayout --username=<svnuser> --include-paths=<path2include> http://svn.server.h
ome/svn/<repo>
git svn fetch --all



To get the branches, checkout them locally:

for remote in `git branch -r |grep -v tags | sed -e 's#origin/##'`; do
  git checkout --track -b $remote
done

Now create the tags, which are branches from the import from SVN:
for remote in `git branch -r |grep tags`; do
  ref=`git show-ref $remote |awk '{print $1}'`;
  tag=`echo $remote |awk -F / '{print $(NF)}'`;
  git tag $tag $ref;
done

Add the new GIT repo as a remote and push the branches and the tags:

git remote add <name> http://git.server.home/scm/git/<targetRepoInGit>
git push --all <name>
git push --tags <name> 


Now the Repo is on the GIT-Server http://git.server.home/.