Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Last active December 5, 2017 14:24
Show Gist options
  • Save Trass3r/0ec6f87f4f4d3a696963 to your computer and use it in GitHub Desktop.
Save Trass3r/0ec6f87f4f4d3a696963 to your computer and use it in GitHub Desktop.
svn to git conversion steps
#git conversion:
# init: see 'subgit help configure'
subgit configure --layout auto -T trunk/Project http:/baseurl... FooSubGit
# edit FooSubGit/subgit/config and authors.txt
# in particular take care of
#[svn]
# url = http:/.../trunk/...
# trunk = :refs/heads/master
# # Note: if repos have been moved around you can define the old locations as branches and subgit will connect the dots!
#
# # exclude binaries etc.
# # also see https://issues.tmatesoft.com/issue/SGT-1037
# excludePath = vendor
# excludePath = *.msi
# excludePath = *.obj
# excludePath = bin
# excludePath = lib
# excludePath = debug
# excludePath = release
#
# httpSpooling = true
#
#[translate]
# eols = false
# ignores = false
#
#[daemon]
# idleTimeout = 0
subgit install FooSubGit
# switch to git bash
git clone FooSubGit FooGit
cd FooGit
# fixup tags if necessary
git for-each-ref refs/tags --shell --format='echo git tag -f %(refname:short)_ %(refname:short)~1' | sh
# create local branches
for remote in `git branch -r`; do git branch --track $remote; done
BRANCHES=$(find .git/refs/heads -type f | sed 's|.git/refs/heads/||')
# add refs to svn revisions to commit msgs:
git fetch origin refs/svn/map:refs/notes/commits
# NOTE: can't use --all parameter cause of the notes ref
# NOTE: this HAS to be done first as any other transform loses the connection to these notes
time git filter-branch -f --msg-filter 'cat && echo -e "\n" && git notes show $GIT_COMMIT' --tag-name-filter cat --prune-empty -- $BRANCHES
rm -r .git/refs/notes
# now other filters following pattern:
# time git filter-branch -d workdir -f <ADD YOUR FILTER SET> --tag-name-filter cat --prune-empty -- --all
# remove folders:
# --index-filter 'git rm -q -r --cached --ignore-unmatch -- directory'
# fix line endings
# use RAM disk since this is slow
# strangely without the git add -u it does strange things and adds newer files to first commit
FASTDISKWORKDIR=$TEMP/workdir
time git filter-branch -d "$FASTDISKWORKDIR" -f --tree-filter "echo '* text=auto' > .gitattributes && rm $FASTDISKWORKDIR/index && git reset && git add -u" --tag-name-filter cat --prune-empty -- --all
# cleanup
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
# if the .git folder is still large try
# https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment