How git reflog can recover commits after an accidental git reset --hard
A developer accidentally ran 'git reset --hard HEAD~3' in the wrong repository window, instantly wiping three commits from the working tree. Because Git does not immediately delete unreferenced commit objects, the work was recoverable using 'git reflog', which logs every position HEAD has pointed to and survives a reset. By identifying the correct commit hash in the reflog and running another 'git reset --hard' to that hash, all three commits were fully restored within seconds. The reflog only tracks committed work, however, meaning genuinely uncommitted changes lost to a hard reset have no recovery path. The developer now rehearses destructive Git operations on a disposable repository clone before running them on any codebase they care about.
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