Migrating Subversion to Git



After running subversion for many many years, I’ve finally taken the plunge and migrated everything to git with a local install of gitea The migration took some figuring out but I ended up with a fairly straight-forward script. For more details on my gitea setup are in a previous post Organising Blender Scripts

Map svn users to git users

First create an authors-transform.txt file

  1. Checkout the svn repository and use svn log
svn checkout svn://svn.agjei.xyz/RepoName
cd RepoName
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ../authors-transform.txt
  1. Update the entries be in the correct format: For example:
beyondwatts = beyondwatts <beyondwatts>

Becomes:

beyondwatts = beyondwatts <beyondwatts@beyondwatts.com>

If you have a few repositories to migrate with the same user base, you will only need to do this once. The authors-transform.txt can be reused to migrate each repo.

Migrate the repository

Create a new migrate.sh file with the following contents and update the SVN_LIST, SVN_HOST, GITEA_HOST variables:

#!/bin/bash
SVN_LIST="RepoName"
SVN_HOST="svn.local"
GITEA_HOST="gitea.local"
GITEA_USER="beyondwatts"

for svn in $SVN_LIST
do
  echo "Migrating $svn ..."
  mkdir $svn
  cd $svn
  svn2git svn://$SVN_HOST/$svn --authors ../authors-transform.txt --rootistrunk
  git remote add origin git@GITEA_HOST:$GITEA_USER/$svn.git
  git push -u origin master
  cd ..
  rm -rf $svn
done

Run the script! For small repositories, it should complete fairly quickly. It may take many hours for a large repository!