3 ms·
> What if you can't find it? Funny enough, I just wrote "git-lost-and-found" last week because I'd added a new file (`git add`) but before I created a commit I
by js2 4y ago
> What if you can't find it?
Funny enough, I just wrote "git-lost-and-found" last week because I'd added a new file (`git add`) but before I created a commit I did a `git reset --hard` which deleted the file. It wouldn't have been in the reflog since there was never a commit created. But I knew it would be under .git/objects until the next time a `git gc` runs, so the trick was to just take a look at a few recent blob objects till I found what I was looking for:
https://gist.github.com/jaysoffian/f42f4b1806f65158b404088144fca227 https://gist.github.com/jaysoffian/f42f4b1806f65158b40408814...
Put that in your PATH as `git-lost-and-found` and then you can call it as `git lost-and-found` from inside any repo.
Edit: oh, MJD beat me to it by 6 years but I hadn't seen this when I wrote the gist above:
https://blog.plover.com/prog/git-reset-disaster.html https://blog.plover.com/prog/git-reset-disaster.html
- js2 4y agoI guess I could use `git fsck --lost-found` too. https://git-scm.com/docs/git-fsck https://git-scm.com/docs/git-fsck