git revert
git revert
creates a new commit with the opposite changes of the provided commit. It will pop open the editor with a
predetermined default commit message like Revert "_PREVIOUS_COMMIT_TITLE"
.
The primary use case for git revert
In most cases, you should only use git revert
to undo a big change you made earlier. It may also be called for if the commit you want to “undo” has been deep in the history of the remote instance of a mainline branch for quite some time, and you don’t want to screw up others by force-pushing that branch. In practice, for single smaller commits it’s often best to simply remove the commit from your branch by rebasing and then force-push. If you’re the only developer on your project, you should not hesitate to do this.