Committed too early or to wrong branch? Here’s how to undo commits without losing your work, depending on whether you’ve pushed or not. Scenario 1: Undo Last Commit (Not Pushed Yet) # Keep changes in working directory (most common) git reset –soft HEAD~1 # Now your changes are uncommitted, ready to re-commit # Use case: […]
Tag: git recovery
Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)
Accidentally did ‘git reset –hard’ and lost hours of work? Your commits aren’t deleted – they’re just orphaned. Here’s how to find them. The Magic Command – Reflog: git reflog This shows every HEAD movement in your repository, even deleted commits. Output looks like: a1b2c3d HEAD@{0}: reset: moving to HEAD~3 e4f5g6h HEAD@{1}: commit: Added user […]
Recover a Deleted Commit Without Panic
Commit gone? Not really. git reflog git checkout <hash> Why Git never deletes immediately — it just forgets references.
Why Git Rebase “Loses” Commits (It Doesn’t — You Did)
Commits aren’t deleted — they’re detached. What actually happens Rebase rewrites history Old commits lose branch references They become unreachable, not gone Recovery git reflog git checkout <lost-commit-hash> Lesson If Git feels scary, you’re missing the mental model, not commands.

