Skip to content

Instantly share code, notes, and snippets.

@ankr
Last active December 25, 2015 16:29
Show Gist options
  • Save ankr/7006642 to your computer and use it in GitHub Desktop.
Save ankr/7006642 to your computer and use it in GitHub Desktop.
Convert SVN repo to GIT repo

1. Create local SVN checkout

mkdir svn-repo
svn checkout svn://example.org svn-repo/

2. Create an authors list

Will create a list of all the contributers of the SVN repo.

cd svn-repo/
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ~/svn-authors.txt

However SVN will list the username as both the real name and the email address, so open up ~/svn-authors.txt and edit the file so the lines goes from looking like:

some_user = some_user <some_user>

to this

some_user = Some User <some@user.com>

3. Make a GIT-SVN checkout

# Make temporary clone
mkdir git-repo-tmp && cd git-repo-tmp/
git svn init svn://example.org --no-metadata

# Make it use the authors.txt we created
git config svn.authorsfile ~/svn-authors.txt

# Fetch all the data
git svn fetch

# Now make a normal git clone of your git-svn checkout
cd ..
git clone git-repo-tmp git-repo

# Remove the temporary clone
rm -rf git-repo-tmp

# Remove the deleted repo from remotes
cd git-repo
git remote rm origin

4. More

http://stackoverflow.com/questions/79165/how-to-migrate-svn-with-history-to-a-new-git-repository http://john.albin.net/git/convert-subversion-to-git

@ankr
Copy link
Author

ankr commented Dec 2, 2013

To update the new git remote from the old svn remote:

    1. Do not delete the git-repo-tmp folder as you will need that in the update process.
    1. cd git-repo-tmp && git svn update
    1. cd git-repo && git pull origin remotes/git-svn
    1. git push github master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment