How I solve this problem? Use git fsck
and logging!
First create a file containing lost (unreachable) commits and blobs. (NOTE: if you did something like git gc
then it will garbage collect all of they commits and you won't find them here!)
$git fsck --lost-found > lost_found.commits
That gives you a file like this:
dangling commit dec2c5e72a81ef06963397a49c4b068540fc0dc3
dangling blob f8c2579e6cbfe022f08345fa7553feb08d60a975
dangling blob 0eb3e86dc112332ceadf9bc826c49bd371acc194
dangling blob 11cbd8eba79e01f4fd7f496b1750953146a09502
dangling commit 18733e44097d2c7a800650cea442febc5344f9b3
dangling blob 1e53a5cdb3ecdde27081ec6e8b31e4070106ee05
You can then open this file with you favorite text editor to copy the commit/blog hashes from there. (*cough* vim macros works great for this *cough*)
Now you can log back from this commit with something like git log --oneline <commit hash>
.
Alternatively, gitk, tig, or any other git viewer should work.
In your case if you find the hash for commit F the log will show you something like this,
A---B---E---F
Quick and easy! Now you can find the context behind all of those dangling commits.
P.S. Yes, I know, late post, but oh well, somebody might find it here and find it useful. (Mostly likely me in 6 months when I google this again)
commit --amend
orrebase
and one accidentally orphaned by working with a detached HEAD, say. – Shanahan