Skip to content

Instantly share code, notes, and snippets.

@mrzechonek
Last active August 29, 2016 15:41
Show Gist options
  • Save mrzechonek/7150855 to your computer and use it in GitHub Desktop.
Save mrzechonek/7150855 to your computer and use it in GitHub Desktop.
svn2git.sh
#!/bin/bash
if [ ! -d "$1" ]; then
echo "Please provide a single command to the repository"
echo "Subversion upstream should be cloned with:"
echo " git svn clone --prefix=svn/ -s <url>"
echo "Git upstream should be added with:"
echo " git remote add origin <url>"
exit 1
fi
pushd $1
# pull changes from subversion
git svn rebase --fetch-all
# convert svn tags into git tags
git branch -r | sed -rne 's, *svn/tags/([^@]+)$,\1,p' | while read tag; do
git tag $tag svn/tags/$tag^
done
# convert svn branches into git branches
git branch -r | grep -v 'svn/\(tags\|trunk\)' | sed -rne 's, *svn/([^@]+)$,\1,p' | while read branch; do
git branch --force $branch svn/$branch
done
# push branches to git
git push --all origin
# push tags to git
git push --tags origin
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment