User Tools

Site Tools


Migrating a Subversion repository to Git on your GitLab instance

#! /bin/sh
# Migrating a SVN repository to Git
# This script requires a mapping file (users.txt) in this format:
#username1 = firstname1 lastname1 <email1>
#username2 = firstname2 lastname2 <email2>
# To get a list of the author names that SVN uses, you can run this:
#svn log ^/ --xml | grep -P "^<author" | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt
git svn clone $SVN_repository --authors-file=$authors_file --no-metadata -s $GIT_repository_name
# For a non standard SVN repository:
#git svn clone $SVN_repository --no-minimize-url --authors-file=$authors_file --no-metadata -s $GIT_repository_name --trunk=/
cd $GIT_repository_name
# Moves the tags to be proper Git tags
git for-each-ref refs/remotes/tags | cut -d / -f 4- | grep -v @ | while read tagname; do git tag "$tagname" "tags/$tagname"; git branch -r -d "tags/$tagname"; done
# Moves the rest of the references under refs/remotes to be local branches
git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done
# Push the new GIT repository to the Git server
git remote add origin $GIT_repository_server
git push origin --all
git push origin --tags

Of course you will have to set the variables SVN_repository, GIT_repository_name and GIT_repository_server appropriately.

gitlab/tips/convert-subversion-to-git.txt · Last modified: 2016/01/27 07:15 by cedric