Skip to content

Instantly share code, notes, and snippets.

@shakahl
Forked from stefanfoulis/findauthors.sh
Created October 11, 2015 20:10
Show Gist options
  • Save shakahl/f76c6b7e3145b9dbc2ed to your computer and use it in GitHub Desktop.
Save shakahl/f76c6b7e3145b9dbc2ed to your computer and use it in GitHub Desktop.
How to sync svn to git
#!/usr/bin/env bash
# Run this script inside a SVN checkout of the project
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";

svn to git

This assumes a one way sync from svn to git.

User mapping

In order to convert svn commits to git commit there needs to be a clear mapping between svn and git users. This is accomplished with a simple mapping file. It is possible to map multiple svn users to the same git user.

authors.txt:

Stefan Foulis = stefanfoulis <[email protected]>
stefanfoulis = stefanfoulis <[email protected]>
jonasobrist = ojii <[email protected]>

If you don't want to create this file by hand, you can use the find_authors.sh script below.

git-svn

make a full checkout using git-svn. The -s switch tells git-svn to assume the default trunk, branches, tags layout.:

git svn --authors-file=authors.txt clone -s svn+ssh://myusername@mysvnserver/svn/myproject myproject-gitsvn
cd myproject-gitsvn

push to git:

git remote add origin [email protected]:stefanfoulis/django-filer.git
git push origin --all
git push origin --tags

update from svn:

git svn rebase
git push origin --all
git push origin --tags

Warning

getting changes from git back to svn is hard. try to avoid that. merging changes from svn to git if there are changes in the git branch is annoying. try to avoid that. Make a separate branch for development in git.

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