Skip to content

Instantly share code, notes, and snippets.

@mhujer
Last active December 10, 2015 23:55
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 mhujer/4512118 to your computer and use it in GitHub Desktop.
Save mhujer/4512118 to your computer and use it in GitHub Desktop.
Export files from GIT repository to SVN-like structure
#!/bin/bash
# git-svnlike-export.sh
#
# Simple scripts that allows you to export GIT repository to SVN-like strukture
#
# I created it to check that our SVN repo was properly migrated to GIT.
# I than compared SVN directory with this export with Total Commander's
# synchronize directories feature
#
# Usage ./git-svnlike-export.sh my-git-repo target-dir
#
# Params:
# $1 Git directory to copy from
# $2 Directory to export in SVN like structure
function gitexport {
#$2 branch
#$3 target
echo '-------'
echo 'Working on: '$2
git checkout $2;
mkdir -p ../$1/$3
echo 'Copying to:' $3
tar -cf - . --exclude=./.git | (cd ../$1/$3 && tar xf - )
}
#cd to git repo
cd $1;
git checkout master
#export branches
for branch in `git branch | sed s/" "// | sed s/"* "//`
do
if [ "$branch" = "master" ]; then
TARGET="trunk"
else
TARGET="branches/$branch"
fi
gitexport $2 $branch $TARGET
done;
#export tags
for tag in `git tag`
do
# $2 is target directory
gitexport $2 $tag "tags/"$tag
done;
cd ..;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment