DEV Community

Cover image for I Almost Lost an Entire Blog with git reset --hard (And Git Saved Me)
Alok Ranjan Daftuar
Alok Ranjan Daftuar

Posted on • Originally published at aloknecessary.github.io

I Almost Lost an Entire Blog with git reset --hard (And Git Saved Me)

What started as a routine cleanup became a lesson in Git's resilience — and a reminder that understanding the model matters more than memorizing commands.

The Moment Everything Disappeared

I had a feature branch with a freshly committed blog post. I was tidying up my local repository — something I'd done a hundred times before. Then, almost on autopilot:

git checkout blogs/microservices-by-def
git reset --hard 65515962bc35fe08514f0b1dcad58cb89773bd2d
Enter fullscreen mode Exit fullscreen mode

The terminal didn't flinch. No warning. No confirmation prompt.

My article was gone. Hours of writing — vanished in under a second.

What Actually Happened

Before:   A ── B ── C ── D  ← my blog commit
After:    A ── B ── C  ← pointer moved here (D still exists, orphaned)
Enter fullscreen mode Exit fullscreen mode

Git didn't delete my commit. It just moved the branch pointer. The commit was still there — floating, unreachable, but alive.

The Mental Model That Changes Everything

Git doesn't store files. It stores snapshots. A branch is just a pointer. git reset relocates that pointer — it doesn't destroy history.

The commit persists until garbage collection prunes unreachable objects (which doesn't happen immediately).

The Recovery: git reflog

git reflog show blogs/microservices-by-def
Enter fullscreen mode Exit fullscreen mode
6551596 reset: moving to 65515962bc35...
0434e98 commit: added blog on Microservices by Default
Enter fullscreen mode Exit fullscreen mode

Recovery took one command:

git reset --hard 0434e98
Enter fullscreen mode Exit fullscreen mode

Everything came back.

The Three Reset Modes

Command Working Tree Index HEAD
git reset --soft
git reset --mixed
git reset --hard

--hard rewrites all three areas. That's why my files disappeared.

Quick Decision Matrix

I want to... Use
Undo a local commit git reset
Undo a pushed commit git revert
Recover lost work git reflog
Save work temporarily git stash
Restore a single file git restore
Clean up commit history git rebase -i

Key Takeaways

  1. Commit early, commit often. Small commits are cheap insurance.
  2. Push important milestones. Remote refs survive local disasters.
  3. Learn reflog before you need it. In a panic, you won't have time to read docs.
  4. Never panic after a bad Git command. Most mistakes are recoverable.

The full post covers merge vs rebase, interactive rebase, reword, cherry-pick, stash, git fsck, and why linear history matters for CI/CD.

👉 Read the complete guide on my blog

Top comments (0)