SkyrimForge.com Wiki

Repositories / Convert SVN to GIT

r3

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.

  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]>
  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.

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

This will also set all grafts from the last step "in stone".

Create a tag for the branches

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

The net effect is to tag, for each svn "fake tag" branch $ref, the parent $ref^ if there are no changes in the tag commit itself (in which case it is superfluous), preserving the tagger identity and timestamp in the process

Converting with Ruby

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