How to migrate from Git to SVN
Today I needed to move a project’s source code (preferably with the versioning intact) from a hosted Git-based platform (Atlassian’s Bitbucket in this case) to my own hosted Subversion-based source code platform. After some initial frustration and failure, I finally found the answer to migrating it while keeping all commits and file history intact.
The steps needed are (via your Linux commandline):
git svn clone [svn-repo]
git fetch [git-repo]
git config user.email "[user-email-address]"
git branch tmp $(cut -b-40 .git/FETCH_HEAD)
git tag -a -m "Last fetch" last tmp
INIT_COMMIT=$(git log tmp --pretty=format:%H | tail -1)
git checkout $INIT_COMMIT .
git commit -C $INIT_COMMIT
git rebase master tmp
Because there was quite a lot of commit history, it seems git-svn didn’t quite always get it 100% right. So I had to manually resolve some conflicts. Fortunately, for this, I have TortoiseGit installed, and I simply needed to find the offending file in Explorer, right click and select TortoiseGit > Edit Conflicts. Once I found the conflict, sorted it out, I marked it as resolved, pressed Save, and quit. After that, it’s back to the commandline:
git add [name-and-path-of-conflicted-file]
git rebase --continue
Once the process is complete and your Git-SVN repo is now back up to date, do the following:
git branch -M tmp master
git svn dcommit --rmdir --find-copies-harder