How can I undo an older commit?
There are a couple of ways to "undo" commits in Git. The "reset" command, for example, allows you to restore your project at any previous revision - effectively "undoing" all the commits that came afterwards. If this what you want to achieve, read more about "reset".
A different situation, however, is when you want to undo the effects of only a certain commit - and not discard any commits that came after that one. This is a classic scenario for the "revert" command.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Reverting a Commit
Using the revert command doesn't delete any commits. Quite the contrary: it creates a new revision that reverts the effects of a specified commit:
The syntax to do this is easy. Just use the revert command and provide the commit you want to "undo":
$ git revert 0ad5a7a6
In case you are using the Tower Git client, the revert command is easily available in the right-click menu of a commit item:
Learn More
- Check out the chapter Undoing Things in our free online book
- More frequently asked questions about Git & version control