âŠī¸ Git Revert = Safe Undo
Mistakes happen. Git revert undoes commits safely. No history rewrite, safe for shared branches.
â git reset (Dangerous)
git reset --hard HEAD~1 // 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 # Revert multiple commits git revert abc123 def456 ghi789 # Auto-commit revert git revert --no-edit abc123
â 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.”
