Git revert

You can use the git revert command to safely undo a commit that has already been pushed.

While you can also delete a previous commit from the history using git reset or git rebase -i, it is generally not a good idea because it causes the remote repository to become desynchronized with the local repositories of other members.

Git reset

You can discard commits that you no longer need using the git reset command. You can specify the scope for the reset command by going into reset mode.

There are three primary reset modes:

Mixed mode restores the state of a changed index. Soft mode undoes a previous commit. Hard mode removes all traces of a commit. Below is a breakdown of each reset mode.