So, I’m working on a project that’s using Subversion for version control. My network connection isn’t great, plus subversion is slow, plus git is (so far) pretty awesomely awesome. The way to interact with an SVN repository is via git-svn, that I talked about setting up previously. Everything’s been going great, however I don’t frequently commit to subversion. This week, we started setting up continuous integration for my work, so I did an git-svn dcommit, committing two days worth of changes. I had forgotten that I had made so many changes (including adding hibernate support). I misread the commit messages and thought something bad was happening. Control-C. git log. HEAD is recent. Last commit was….yesterday. Oh. Fuck.
I figure git-svn borked something, so I git-rest --hard. No effect. I’m starting to panic, now. almost 2 days of work lost is not something I’m looking forward to. I hasitly go into Time Machine and get the previous hours’ backup. But, I just hate that solution. I have no idea what happened, and my trust in Git (or my ability to use it) has to be restored. After IM’ing with a co-worker, I got to the bottom of it.
It turns out that I wasn’t paying attention to how git-svn works. What it does when you do a rebase or dcommit (which implicitly does a rebase), is to first undo all your changes since your last rebase/dcommit, and get the changes made to the SVN repository (it even says as much as the first line of the output). It then “replays” your commits to make sure there’s no conflicts.
By hitting Control-C in the middle of that, I manually caused the same situation that would happen if there were conflicts. Git stops, tells you to resolve conflicts, and asks you to git-rebase --continue. If I had just git-rebase --continue‘ed, I would be fine. Since I did a hard rest, I figured I was fucked. Enter the log.
.git/logs/HEAD contained information about all activity, including my missing commits. I grab the version numbers (which, in Git, are hashes of the entire repository), do a git-reset --hard big.honkin.git.hash.version and viola! everything’s back to how it was (the command ran instanteously, to boot).