Repositories / Convert SVN to GIT

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 #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!

  • 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:// | 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.
  • Run the following command to import the SVN repository into a GIT repository:
    git svn clone -A author-map --no-metadata -s svn:// project
    NOTE: You may need to omit the -s from the above command.
  • Fix up the history until satisfied.
  • Change the repository on the web-page to GIT.
  • 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

  • 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".

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

Create a tag for the branches

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

You must login to post a comment. Don't have an account? Register to get one!

  • Avatar of Bevalharry Bevalharry Jul 31, 2015 at 15:38 UTC - 0 likes
    Remarkable content, decided in front of you and additionally book marked your blog post. Document can’t simply wait to read a great deal more right from you will. read more
  • Avatar of johndravid johndravid Jul 29, 2015 at 17:52 UTC - 0 likes
    The best article I came across a number of years, write something about it on this page. Qatar Advertising Agency
  • Avatar of ChanaAmelia ChanaAmelia Jun 16, 2015 at 03:58 UTC - 0 likes
    I am glad to read it and being able to reveal my ideas in here. I want to say that this article is amazing, great written and come with approximately all technology info. I'd like to read more posts like this! thanks for sharing this! keep on blogging see us:buy facebook fans
  • Avatar of Farmbuyer Farmbuyer Aug 03, 2012 at 20:06 UTC - 0 likes

    Similar steps can be done for converting from SVN to HG, but I recommend that you only convert the trunk, not the entire trunk+tags+branches repository. Until curseforge/wowace ticket 3048 is fixed, converting the tags means that every subsequent tag will cause all tags to be packaged.

  • Avatar of Quaiche Quaiche Mar 03, 2009 at 17:34 UTC - 0 likes

    As said at the very top of this page, current Windows distros of git do not have git-svn included. When I do this conversion myself, I do the 'git svn' part on my Ubuntu box, then push it up, and pull it back down onto my windows machine.