Skip to content

Instantly share code, notes, and snippets.

@awbauer
Created November 18, 2014 17:13
Show Gist options
  • Save awbauer/70cdaaf1445ae82664a4 to your computer and use it in GitHub Desktop.
Save awbauer/70cdaaf1445ae82664a4 to your computer and use it in GitHub Desktop.
SVN ==> GIT Migration

This document details the procedure for a permanent migration from SVN to Git.

Overview

  1. Create authors file to map usernames to authors
  2. Clone SVN repository to Git using git svn
  3. Severe connection to SVN remote
  4. Convert tag branches to Git tags
  5. Set up Github remote as origin and push

Procedure

# Checkout the original repository
$ svn checkout [SVN repo path]
$ cd repo-name

# Get list of committers for authors.txt file
$ svn log --quiet | awk '/^r/ {print $3}' | sort -u > ../authors.txt

#
# Edit "authors.txt" to match the following format:
#
# {{ svn username }} = {{ git name }} <{{ git e-mail}}>
#
# e.g.
# joeuser = Joe User <joeuser@bu.edu>
#

# Clone SVN repository using Git
$ git svn clone [SVN repo URL] [temporary working dir] --stdlayout --no-metadata --authors-file=authors.txt

#
# NOTE: It will fail if it encounters any user names that are not in authors.txt.
# If this occurs, add the missing author(s), remove the newly-created git directory, and restart the clone.
#
# NOTE 2: Authorless commits will fail, as above. Workaround: add the following to the authors.txt file: 
# (no author) = no_author <no_author@no_author>

# Setup local branches for all remotes
$ git fetch . refs/remotes/*:refs/heads/*

# Delete all remote branches
$ for branch in `git branch -r`; do git branch -rd $branch; done

# Delete local "trunk" branch
$ git branch -d trunk

# Remove git-svn configuraiton / files
$ git config --remove-section svn-remote.svn
$ rm -Rf .git/svn/

# Set up Git tags for each of the tag branches, then remove those branches
# e.g.
$ git tag -am 'Release 1.4.4' 1.4.4 02b0e0e0b8
$ git branch -D tags/1.4.4

# Set up Github remote as origin and push
$ git remote add origin [GIT URL]
$ git push origin --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment