I ran git reset --hard
What just happened
reset --hard moved your branch to another commit and overwrote your working directory. Commits are still reachable through the reflog. Changes that were never staged are gone from Git's point of view.
Potential risks
- Running another reset --hard on top can make things worse.
- Never-staged changes cannot be recovered by Git.
Before you run anything
- Stop typing commands at random. Breathe.
- Check your IDE local history (VS Code Timeline, JetBrains Local History) for unstaged work.
- Golden rule: before any destructive command, create a safety branch with git branch backup/before-fix โ it costs nothing.
Recovery steps
- 1
Find where you were
The line just below โreset: moving to โฆโ is usually the state you want (HEAD@{1}).
Safe$ git reflog -n 15 - 2
Rescue it on a new branch
Safer than resetting again: you can inspect the rescued branch before doing anything else.
Safe$ git branch rescue HEAD@{1}$ git log --oneline -n 5 rescue - 3
Look for lost staged files
Files that were git add-ed survive as dangling blobs. Inspect them one by one with git show.
Safe$ git fsck --lost-found$ git show <blob-hash> - 4
Move your branch back
Once rescue looks right. This discards any current uncommitted change.
Destructive$ git reset --hard rescue
These procedures are provided for information only. Read each command and adapt it to your situation before running it. Disclaimer