Skip to content

Instantly share code, notes, and snippets.

@rca
Forked from colszowka/svn2git_migration.sh
Created September 28, 2011 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rca/1249273 to your computer and use it in GitHub Desktop.
Save rca/1249273 to your computer and use it in GitHub Desktop.
svn to git migration notes
#
# Migration tool from SVN to git
# ==============================
# (c) 2009 Christoph Olszowka, Capita Unternehmensberatung
#
# This is not meant for usage in an actual shell script - you're better off running
# each individual block (marked by the comments) separately and check the output to see if everything
# went right - this is more a writeup of the required steps so I can remember them rather than a
# shoot-and-forget-solution.
#
# Sources:
# ========
# http://blog.woobling.org/2009/06/git-svn-abandon.html
# http://www.simplisticcomplexity.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/
# http://www.bytetrap.com/blog/2008/06/07/slimming-down-git-repository/
#
# To start off, create temporary dir where all the action will take place. This can be removed when the
# finished git repository has been pushed to the remote server.
mkdir svn2git-tmp
cd svn2git-tmp
#
# Extract the whole actual svn repository (dumped from your remote server) to "svn-repo"
# inside your temp directory now! (i.e. svn2git-tmp/svn-repo/
#
#
# Create authors mapping from svn to git - replace with your actual usernames.
# The git svn clone command will complain and abort if you forget someone here!
#
ruby -e "File.open('authors.txt', 'w+') { |f| f.puts \"johndoe = John Doe <john.doe@example.com>\nfoobar = Foo Bar <foo.bar@example.com>\" }"
#
# Get svn abandon tool scripts for fixing tags, merges and do magic ;)
# see http://blog.woobling.org/2009/06/git-svn-abandon.html
#
git clone git://github.com/nothingmuch/git-svn-abandon.git
#
# Checkout the local copy of the SVN repository (make sure it is in place in svn2git-tmp/svn-repo before, see above!),
# using our predefined authors file
# See http://blog.woobling.org/2009/06/git-svn-abandon.html
#
mkdir svn-clone-tmp
cd svn-clone-tmp/
git svn clone --prefix=svn/ --stdlayout --authors-file=../authors.txt file://`pwd`/../svn-repo .
#
# Apply cleanup scripts
# See http://blog.woobling.org/2009/06/git-svn-abandon.html
#
# In order to wor the git-svn-abandon scripts needed to live alongside
# the other git commands in the libexec directory, e.g. /usr/local/libexec/git-core
cp ../git-svn-abandon/git-svn-abandon* /usr/local/libexec/git-core/
git svn-abandon-fix-refs
git svn-abandon-cleanup
#
# Do a fresh clone of our new local git/svn repository
#
cd ..
git clone svn-clone-tmp git-clean
cd git-clean/
#
# Slim down by rebuilding deltas (optional, see http://www.bytetrap.com/blog/2008/06/07/slimming-down-git-repository/)
#
git repack -a -d -f --depth=250 --window=250
#
# Remove original (svn) remote origin, add new, git-only one and push everything to the server
# (which, of course, should be initalized with 'git init --bare')
#
git remote rm origin
git remote add origin git@example.com:repository.git # Replace this with actual repository location on remote server
git push --all
git push --tags
#
# Miscallaneous
#
# Use the following inspection tools to find out if your tags have been imported properly!
#
# You can also use this tiny Ruby script to list all tags and their commit messages at once:
# http://gist.github.com/139429
#
# List tags
git tag -l
# Show tag revision identifier
git rev-parse release_1.0 => 2d3321b...
# Show revision log
git cat-file -p 2d3321b
# Show branches
git branch -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment