At Eljakim (my new employer), work repositories are all svn (lowest common denominator), but several of us access them via git-svn. I’ve created a couple of new ones recently, but thanks to timezones, I never get an svn repo until I’ve already done a day’s work (in git). Getting those commits into svn without losing history is a simple thing when you know how – but when I googled, all I saw were strange and crazy hacks involving arcane commands I didn’t understand. So, here’s the easy way:
- Check out the svn repo
- Make a folder for your work (assuming it’s not already there)
- Check out just that folder
- Connect it to the git repo
- Rebase your work on top of svn
- Clean up the temp file (is thre a way to just commit an empty dir in git?)
- And send it to the server!
- Switch back to the primary repo (optional)
git svn clone https://url.to/svn-repo
cd svn-repo
mkdir chani
touch chani/temp
git add chani/temp
git ci
git svn dcommit
cd ..
git svn clone https://url.to/svn-repo/chani merge-repo
cd merge-repo
git remote add mygit /path/to/git-repo
git fetch mygit
git checkout -b mymerge mygit/master
git rebase master
git checkout master
git merge --ff-only mymerge
git rm temp
git ci
git svn dcommit
cd ..
rm -rf merge-repo
cd svn-repo
git svn rebase
Of course, you don’t have to delete the merge repo, you could keep using it as your primary repo – but the way things are set up here I always end up wanting my checkout to be a level above that. :)
Edit: Also, make sure you move or delete the original git repo once the commits are safely in svn. I spent half the day continuing to work in the pure git repo after blogging this… >.< oh well, at least I just had to copy&paste off my blog to fix it. :P