git revert
Undo a commit with a new commit, without rewriting history
What it does
git revert creates a new commit that does the opposite of the one you name: it removes the lines that commit added and brings back the ones it removed. The old commit stays in history. git opens an editor with a ready message; --no-edit keeps it as is.
That makes revert the safe way to undo something already on the server: history only grows, and nothing breaks for your teammates. For commits only you have, git reset works too. If the undone changes overlap with later ones, you may get a conflict, as in a merge.
Syntax
git revert <commit>
git revert --no-edit <commit>Examples
Create a commit that undoes the last commit
git revert HEADrevert— a new commit with the opposite changesHEAD— which commit to undo