Hacker News new | ask | show | jobs
by cesarb 3486 days ago
> so I went through file by file staging it all

When you stage a file in git, what it actually does is to create in its object database a blob with the contents of the staged file, and then it points the corresponding entry in the working tree index to the blob's hash. The blob object is only removed during the periodic garbage collection, and only after a configurable period of time since its creation has passed.

Therefore, once you stage a change, git will keep a copy of it for at least two weeks unless configured otherwise. Even if nothing points to it anymore (due to, for instance, an errant git reset --hard), there are ways to find its object hash (something like git fsck --unreachable, or even a ls -lR in the object database directory), and once you have the hash, you can use git cat-file to retrieve its contents.

2 comments

Result! git fsck --unreachable has pulled up the stray commit. There it all is, right in front of me. Incredible! Thanks.
Seriously? Wow! I will try that first thing tomorrow. Thanks.
Look up git reflog or so.