Undo Git mistakes

Undo your last commit (not pushed yet)

Take back the last commit. Keep the changes to fix them up, or throw them away.

  1. Undo it but keep the changes
    Terminal
    git reset --soft HEAD~1

    Your changes stay staged, ready to commit again.

  2. Or undo it and throw the changes away
    Terminal
    git reset --hard HEAD~1

    This deletes the changes for good. Already pushed? Use Undo a commit you already pushed instead.

Check it worked

  1. See your latest commits
    Terminal
    git log --oneline -5
  1. Undo it but keep the changes
    Terminal · Ubuntu / Debian
    git reset --soft HEAD~1

    Your changes stay staged, ready to commit again.

  2. Or undo it and throw the changes away
    Terminal · Ubuntu / Debian
    git reset --hard HEAD~1

    This deletes the changes for good. Already pushed? Use Undo a commit you already pushed instead.

Check it worked

  1. See your latest commits
    Terminal · Ubuntu / Debian
    git log --oneline -5
  1. Undo it but keep the changes
    PowerShell
    git reset --soft HEAD~1

    Your changes stay staged, ready to commit again.

  2. Or undo it and throw the changes away
    PowerShell
    git reset --hard HEAD~1

    This deletes the changes for good. Already pushed? Use Undo a commit you already pushed instead.

Check it worked

  1. See your latest commits
    PowerShell
    git log --oneline -5