tags:

views:

20

answers:

1

I suspect I have performed an incorrect amendment (B') of last commit (B), which cause all my work in the last commit (B) gone.

  A
  |
  B [master]

amend to 
     A
   / |
  B  B'
    [master]

I think if I haven't do any git gc, my original "correct" commit (B) should still in the repository. However, because it is not referred directly/indirectly by any ref, I cannot find it out. Is there any way that I can list out such kind of "unreferred" commit in git so that I can retrieve my work from that commit?

Thanks

+2  A: 

Yes, the reflog is what you're looking for. The reflog keeps a record of the previous value of a branch every time the branch HEAD changes.

Greg Hewgill
If you've managed to get to where the commit isn't even in the reflog anymore, there's still hope - it's a job for `git fsck`, which can list dangling objects!
Jefromi