↩️ git revert = Safe Undo
git reset changes history. git revert creates new commit that undoes changes. Safe for shared branches.
❌ git reset (Rewrites History)
git reset --hard HEAD~1 // Danger: rewrites history
✅ git revert (Safe)
git revert HEAD // Creates new commit undoing changes
📝 Revert Commands
# Revert last commit git revert HEAD # Revert specific commit git revert abc123 # Revert with message git revert -m "Reverting feature X" abc123 # Revert without commit (stage only) git revert -n abc123 # Revert range of commits git revert abc123..def456 # Revert merge commit git revert -m 1 merge-commit-hash # Continue revert (after resolving conflicts) git revert --continue # Abort revert git revert --abort
💡 Reset vs Revert
- Reset: Rewrites history (dangerous for shared branches)
- Revert: Creates new commit (safe for shared branches)
- Use revert for public branches
- Use reset for local, unpushed commits
- Revert is reversible (revert the revert)
“git revert safely undoes commits. No history rewrite. Essential for shared branches.”





