Monday, July 19, 2010

Recover lost commits from a Git repository

This morning I managed to blast away a colleagues local commits. We were running into ``non-fast-forward`` errors when pushing and somehow I lost one of the local commits (which I'm still curious how I screwed that up). Anyway, I use the technique I wrote about almost 3 months ago (to the day!): "Recover a deleted branch from a Git repository"

The main difference was I was not after the dangling commit, but the commit just before for it (which would show after the dangling commit in ``git-log``).

So I use that command I borrowed from StackOverflow:

$> git fsck --full --no-reflogs | grep commit

Then, use ``git log --stat <commit-hash>`` on the identified hashes and look for the following commit that you're after.

I will 100% admit that this is in the realm of MacGyver - but I didn't want to be responsible for blowing away any of my co-workers code.

1 comment:

Unknown said...
This comment has been removed by the author.