Want to undo your previous commit with a git revert?
Want to keep your old commit but start fresh? Then you want to revert a git commit instead of an amend or a reset.
The benefit of the git revert when you undo a commit is that it keeps your old commit, undoes changes, and then creates a new commit for you. This way no history is lost, and you don't have to worry about messing up the git commit history when you push back to GitHub or GitLab.
Compare this to when you undo a commit with reset or amend instead of the git revert command. In those other cases, you end up with orphan commits that can really mess up remote repositories.
To undo your last commit, git revert the changes. It's the best option!
![](https://s2.save4k.ru/pic/qdL8uaz_-n0/maxresdefault.jpg)