You ran `git reset --hard` and lost uncommitted-then-committed work. Can you get it back?
IntermediateScenarioUndoing Mistakes
Answer
Situation read → If the work was ever committed, the commits still exist as unreachable objects and the reflog records where HEAD was.
What I'd do →
git reflogand find the entry before the reset, such asHEAD@{2}.- Restore:
git reset --hard HEAD@{2}, or safer,git branch rescue HEAD@{2}. - Verify with
git log rescue.
Why → Reflog entries last 90 days for reachable and 30 days for unreachable commits by default.
Interview tip → Work that was never staged or committed is gone; reset --hard cannot be undone for those changes.
More on Undoing Mistakes
You committed on `main` when you meant to be on a feature branch. Nothing is pushed. Fix it.BeginnerYou made a typo in your last commit message and have not pushed.BeginnerA bad commit is already on shared `main`. Others have pulled it. How do you undo it?IntermediateYou need to revert a merge commit on `main`. `git revert` says "commit is a merge but no -m option was given".IntermediateYou deleted a local branch with unmerged work by mistake.BeginnerAfter `git stash pop` you got conflicts. Is your stash lost?Intermediate