Undo Git mistakes

Revert an older commit that is already pushed

Cancel out one commit from further back in the history, without rewriting what others already have.

Fill these in once
  1. Find the commit you want to undo
    Terminal
    git log --oneline -15

    Copy the short ID at the start of its line.

  2. Make a new commit that reverses it
    Terminal
    git revert a1b2c3d

    Git opens an editor for the message. Save and close it to finish.

  3. Share it
    Terminal
    git push

Check it worked

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

    The top commit starts with Revert.

Undo it
  1. Stop a revert that hit a conflict
    Terminal
    git revert --abort
  1. Find the commit you want to undo
    Terminal · Ubuntu / Debian
    git log --oneline -15

    Copy the short ID at the start of its line.

  2. Make a new commit that reverses it
    Terminal · Ubuntu / Debian
    git revert a1b2c3d

    Git opens an editor for the message. Save and close it to finish.

  3. Share it
    Terminal · Ubuntu / Debian
    git push

Check it worked

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

    The top commit starts with Revert.

Undo it
  1. Stop a revert that hit a conflict
    Terminal · Ubuntu / Debian
    git revert --abort
  1. Find the commit you want to undo
    PowerShell
    git log --oneline -15

    Copy the short ID at the start of its line.

  2. Make a new commit that reverses it
    PowerShell
    git revert a1b2c3d

    Git opens an editor for the message. Save and close it to finish.

  3. Share it
    PowerShell
    git push

Check it worked

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

    The top commit starts with Revert.

Undo it
  1. Stop a revert that hit a conflict
    PowerShell
    git revert --abort