Undo Git mistakes

Undo a commit you already pushed

Safely cancel out the last commit on GitHub with a new commit, without rewriting history.

  1. Make a commit that reverses the last one
    Terminal
    git revert HEAD --no-edit
  2. Share it
    Terminal
    git push

Check it worked

  1. See the history
    Terminal
    git log --oneline -3

    The top commit says Revert, followed by the one it undid.

Undo it
  1. Bring the change back
    Terminal
    git revert HEAD --no-edit

    Reverting the revert puts the original change back.

  1. Make a commit that reverses the last one
    Terminal · Ubuntu / Debian
    git revert HEAD --no-edit
  2. Share it
    Terminal · Ubuntu / Debian
    git push

Check it worked

  1. See the history
    Terminal · Ubuntu / Debian
    git log --oneline -3

    The top commit says Revert, followed by the one it undid.

Undo it
  1. Bring the change back
    Terminal · Ubuntu / Debian
    git revert HEAD --no-edit

    Reverting the revert puts the original change back.

  1. Make a commit that reverses the last one
    PowerShell
    git revert HEAD --no-edit
  2. Share it
    PowerShell
    git push

Check it worked

  1. See the history
    PowerShell
    git log --oneline -3

    The top commit says Revert, followed by the one it undid.

Undo it
  1. Bring the change back
    PowerShell
    git revert HEAD --no-edit

    Reverting the revert puts the original change back.

New to rollbacks? I explain it in plain English on Layman Terms.