How to undo a pushed commit with git revert

Run git revert <commit-id>, then git push. Revert creates a new commit that does the exact opposite of the one you name. Nothing is deleted, so it's safe on branches your teammates already have.

Step by step

  1. Find the id of the commit to undo:

    $ git log --oneline
  2. Create a commit that undoes it:

    $ git revert a1b2c3d
  3. Share the fix:

    $ git push

Never use git reset to remove a commit you already pushed: your branch and everyone else's would diverge. Revert is the team-friendly undo.

Try it in the interactive sandbox →Practice “Revert it” with a real repository and teammates, right in your browser.

Related guides