git lost-found and no branchMon, Jun 30, 2008 dev ops
After a little hacking session and some unpleasant ruby 1.8.6 vs 1.8.7 fun, I ran into another interesting tidbit about git.
As with most powerful tools it will gladly allow you to blast your foot off. Wouldn’t ya know, my aim was well aligned with my feet a few moments ago.
git checkout some/remote_branch. I thought I was switching over to a remote branch I’d created on another machine,
so that I could test and work on this other machine. Little did I know that I had entered the "(no branch)" state.
At this point I was pretty much gunning to create orphaned blobs, commits and other such items. After creating a few,
I wanted to push those changes to the upstream server (github in this case) after merging them into the HEAD.
After checking out the master branch, I quickly found out that my little "(no branch)" wasn’t reachable. A little poking around git rendered,
git fsck --lost-found, which will identify orphaned commits and entities. Once you find the commit id you can checkout the master branch again and
git merge my-lost-commit-id-here.