SkyrimForge.com Wiki

Repositories / Convert SVN to GIT

r5

Note: This article currently has a high "know what you do" factor, and servers mostly as an outline of what to do and how to automate some of the tedious steps. If you have any questions, feel free to drop by on irc.freenode.net #curseforge and ping charon.

Converting a SVN repository to GIT

Note: You may need to use git-svn on Linux as there are reports that it is broken on Windows. YMMV. You can also try both the mingw port and a cygwin install and see if at least one works.

Do not switch your repository type to Git before you are satisfied with the conversion result, so that you can re-clone if something goes wrong!

  1. Develop an author map file which contains the lines for each user who has submitted a commit to your SVN repository:
svnuser = R. E. Alname <[email protected]>

You can automate some of the task by running

svn log svn://svn.wowace.com/wow/fu-bar_reagent-fu/mainline | sed -ne 's/^r[^|]*| \([^ ]*\) |.*$/\1 = \1 <\[email protected]>/p' | sort -u > author-map

which will scan the SVN history for all users, and make a dummy line for each. You can then look up their real names and emails as required.

  1. Run the following command to import the SVN repository into a GIT repository:
git svn clone -A author-map --no-metadata -s svn://svn.url.com/game/project/mainline project
  1. Fix up the history until satisfied.
  2. Change the repository on the web-page to GIT.
  3. Run the following commands to add your GIT repository:
git remote add origin [email protected]:game/project/mainline.git
git push origin master

How to fix the history

Remove useless commits

Transition from old repository to new repository

  1. Make a graft that removes the commits that you do not want.

Grafts are "fake parents" and can be used to remove emtpy commits, glue together disconnected history and even rebuild (simple) SVN merges as "real" Git merges. See man gitrepository-layout for usage.

Remove the project name from commit notes

On the old repository, you had to preface all your commit notes with the project name. This will get rid of them all. It will also drop empty commits, and set all grafts from the previous step "in stone".

  1. Run the command:
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' --tag-name-filter cat --msg-filter 'perl -pe "s/^project:\s*//"' -- --all

Create a tag for the branches

  1. Run the following command:
git for-each-ref --format="%(refname)" refs/remotes/tags/ | while read tag; do GIT_COMMITTER_DATE="$(git log -1 --pretty=format:"%ad" "$tag")" GIT_COMMITTER_EMAIL="$(git log -1 --pretty=format:"%ce" "$tag")" GIT_COMMITTER_NAME="$(git log -1 --pretty=format:"%cn" "$tag")" git tag -m "$(git log -1 --pretty=format:"%s%n%b" "$tag")" ${tag#refs/remotes/tags/} "$tag"; done

The net effect is to convert SVN "tags" to annotated Git tags, preserving the tagger identity and timestamp.

Converting with Ruby

Please see this page for information on how to do this with Ruby.