git reset & git revert
Both commands undo changes but in opposite ways. reset rewrites history by moving the branch pointer backward — local only, destructive. revert creates a new commit that undoes a previous one — safe for shared branches because it adds to history rather than rewriting it.
01.The Three Modes of git reset
--soft: Move HEAD back but keep all changes staged. Use this to "undo" a commit and recommit differently. --mixed (the default): Move HEAD back and unstage changes but keep the file modifications. Use this to redo commits with different groupings. --hard: Move HEAD back AND discard all changes in files. Use only when you are absolutely certain you want to throw changes away.
02.git revert: The Collaborative Undo
revert is safe to use on shared branches because it only adds a new commit — it never rewrites existing history. If commit X added a function, reverting X creates a new commit that removes it. The original commit X is permanently preserved. Your colleagues who have pulled the original commit are unaffected. This is the only way to "undo" on main or shared branches.
Commands
Why is git revert safer than git reset on a shared branch?