Go Back
ยท1 Min Read

Undo Last Commit in Git

Two ways to undo your last commit depending on whether you want to keep your changes.

Sometimes you commit too early or make a mistake. Here's how to fix it.

Keep Your Changes

If you want to undo the commit but keep your files modified:

git reset --soft HEAD~1

Your changes stay staged, ready to commit again.

Discard Everything

If you want to throw away the commit and all changes:

git reset --hard HEAD~1

Be careful - this deletes your work permanently.

Which One To Use

  • Made a typo in the commit message? Use --soft
  • Committed the wrong files? Use --soft
  • Want to start over completely? Use --hard