How to recover a dropped Git stash using git fsck before garbage collection
Accidentally dropping a Git stash does not immediately delete the underlying commit objects, as Git removes only the reference pointing to them. The git fsck command can scan the object database and surface these now-unreferenced commits, typically returning two hits per dropped stash. Developers can identify the correct stash commit by checking which unreachable commit has two parents, a structural trait unique to stash entries. Once the SHA is found, git stash apply can restore the changes directly without needing a named ref. However, recovery is time-sensitive, since running git gc will permanently prune orphaned objects once the default expiry window passes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in