Skip to content

Instantly share code, notes, and snippets.

@jamiehs
Last active December 11, 2015 20:48
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 jamiehs/4657886 to your computer and use it in GitHub Desktop.
Save jamiehs/4657886 to your computer and use it in GitHub Desktop.
Routine for converting svn to gitIf you have any other tips and or ideas, please let me know.
username1 = User Name <user@domain.com>
username2 = User2 Name <user2@domain.com>
otheruser = Other User <other_user@domain.com>
other = Developers <developers@domain.com>
# In your SVN repository, run this command to get all your authors.
# This is a very important step. The rest of the process may silently fail otherwise.
# This is a nice easy way to get the authors for a SVN repo:
svn log --quiet | awk '/^r/ {print $3}' | sort -u
# Compile an authors.txt file using the format in the authors.txt file provided.
# Git needs this information while SVN only needs a username.
# Clone the repo, trunk, branches, tags
# Do not provide the trunk URL here, but provide the "root"
# repo URL that lies one level up from the trunk/tags/branches
# eg: https://myuser.myrepohost.com/myrepo/
# Enter the path to the Tags, Branches, and Trunk using -t -b -T respectively.
git svn clone <repository URL> --no-metadata -A authors.txt -t tags -b branches -T trunk <local git repository directory name>
# Fill in any empty commit messages.
# You'll need to do this for each branch by
# checking out that branch and then running this:
git filter-branch -f --msg-filter '
read msg
if [ -n "$msg" ] ; then
echo "$msg"
else
echo "<empty commit message>"
fi'
# Checkout other branches by specifying the remotes/<branch name>
# Use `git branch -a` to see the local and remote branches
git checkout -b <branch name> <remote>/<branch name>
# Once done, then it might be a good time to nuke the svn info
# The Git Book reccommends this for converting the branches:
# http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git
# Move the rest of the references under refs/remotes to be local branches:
git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done
# Clone the repo into a new repo and then remove the remote.
# This makes a new pristine repository with no remotes, but all of the history.
# http://nathanhoad.net/how-to-migrate-your-svn-repository-to-git
git clone converted-repo-folder-name new-repo-folder-name
cd new-repo-name
git remote rm origin
# You should now have a pristine copy of the Git repository
# with no remotes and all of your SVN history!
# Add your new remote
git remote add origin git@example.com:/repository-name.git
# Push your local branch (usually master) to the origin
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment