git revert
The "revert" command helps you undo an existing commit.
It's important to understand that it does not delete any data in this process: instead, Git will create new changes with the opposite effect - and thereby undo the specified old commit.
Important Options
<commit-hash>
Specifies the commit you want to undo. Note that you can also provide multiple commit hashes if you want to revert multiple commits in one go.
--no-commit
Does not directly commit the created changes. By default, the reverting changes would be directly committed by Git. With the "--no-commit" option, the changes will only be created, but not committed. You could then edit them further and commit them manually.
--no-edit
Use the default commit message that Git suggests. By default, you would be prompted to enter a commit message for the new commit that is about to be created in the process. Using "--no-edit", however, you signal that you do not want to provide your own message, but simply go with the standard message that Git proposes.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Usage Examples
Simply provide the hash of the commit you want to undo:
git revert a72ef02
Git will then create changes that have the exact opposite effect of the changes contained in this original commit - effectively undoing them. Use the "--no-commit" option if you want to inspect (and possibly further modify) these changes and commit them manually:
git revert a72ef02 --no-commit
Tip
Right-Click to Revert
With the Tower Git client, reverting commits (and using many other "undo" tools in Git) becomes a breeze:
Try it free for 30 days and see why 100,000 developers all over the world use Tower to be more productive with Git!
Learn More
- Check out the chapter Undoing Things in our free online book
- Find the full command description in the Git documentation
- More frequently asked questions about Git & version control