Anyone ever lost uncommitted work after git reset --hard?
I just lost three hours of work... I habitually only ran add and never committed.
Does anyone know how to recover it? ㅠㅠ
7 answers
T_T I've been there too, so since then I've made sure to commit every 10 minutes no matter what
If you use VSCode, check out the Timeline tab. It keeps local history, so you might be able to recover it. IntelliJ also has Local History.
Does reset --hard really wipe out uncommitted work? That's not quite right. --hard resets tracked files to the HEAD state, and it doesn't touch newly created untracked files. I'd say the first step is to figure out exactly what you actually lost.
You said you ran git add, right? Then we can recover it. Run git fsck --lost-found and you'll get a list of dangling blobs. Open each one with git cat-file -p <hash> and look through them to find it. The moment you add a file, its contents are saved as an object. Even if you didn't commit, it was staged. The catch is that the filename info is gone, so you'll have to dig through blobs that contain only content. If you've been at it for three hours, there probably aren't many files left, so you should find it quickly. Don't run any more commands in that repo from now on. If gc runs, it's really over.