Git Cheat Sheet · Integrate
Undo a published commit
git revert <commit>
To undo a commit already published, use git revert <commit>. Git creates a new commit that does exactly the opposite. History is not rewritten: nobody has to realign their copy, and the fix is pushed normally.
What it does
Creates a new commit that undoes the changes of an old one, without rewriting history.
A use case
A commit already pushed to main breaks production: you undo it cleanly.
On the command line
git revert <commit>- Creates the undo commit and opens the editor for its message.
git revert --no-edit <commit>- Keeps the suggested message ("Revert …").
git revert -n <a> <b>- Undoes several commits in a single commit.
git revert -m 1 <merge>- Undoes a merge commit, keeping the first parent.
In Merathon
- Right-click the commit in the graph → "Revert this commit".
Frequently asked questions
What is the difference between git revert and git reset?
git revert adds an inverse commit: safe on a shared branch. git reset moves the branch and removes the following commits from history: only for unpublished commits.
How do I undo a revert?
By reverting the revert commit.