Algocraft / Git Commands / git reset vs revert

git reset vs git revert

Two ways to undo — one moves the branch pointer backwards (and can discard work), the other adds a new commit that cancels the old one out

soft / mixed / hard History-Safe Revert
Commit Graph Step 0 / 0
Working Directory → Staging → Repository
Terminal Transcript

Key Concepts

🎯 When to Use
  • Reset: undo local, not-yet-shared commits
  • Revert: undo something already pushed/shared with others
⚖️ The Three Reset Modes
  • --soft: move pointer, keep index + working dir
  • --mixed (default): move pointer, unstage, keep working dir
  • --hard: move pointer, wipe everything to match
🎓 Pro Tips
  • "Uncommit but keep my changes staged" = reset --soft HEAD~1
  • Reset a public branch and everyone else's history silently forks from yours