Repositories / Convert SVN to GIT


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

  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:// 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.

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:
gfb: git filter-branch --tag-name-filter cat --msg-filter 'perl -pe "s/^project:\s*//"' -- --all

Create a tag for the branches

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

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.