git reset rewrites history – dangerous on shared branches. git revert creates new commit that undoes changes safely.
❌ Wrong – git reset on Shared Branch:
git reset --hard HEAD~1 # Removes commit from history git push --force # DANGEROUS - rewrites history for everyone! # Team members' branches now out of sync
✅ Right – git revert:
git revert HEAD # Creates NEW commit that undoes last commit git push # Safe - just adds new commit, doesn't rewrite history # Result: Commit stays in history, but its changes are undone
Revert Multiple Commits:
# Revert last 3 commits git revert HEAD~2..HEAD # Revert specific commit git revert abc1234
Revert without Committing:
git revert -n HEAD # Stage changes but don't commit # Edit files if needed git commit -m "Revert with modifications"
Rule: Local branch = reset OK, Shared branch = revert only!
