Keep changes, remove commit

Keep staged changes

git reset --soft HEAD~1

Example:

git reset --mixed HEAD~1

Unstage everything but keep files

git reset HEAD~1

Example:

git status

Edit the last commit

Amend commit message only

git commit --amend -m "better message"

Example:

git commit --amend --no-edit

Amend with additional files

git add src/auth.js
git commit --amend

Example:

git show --stat HEAD

Discard commit and changes

Drop last commit completely

git reset --hard HEAD~1

Example:

git reset --hard origin/main

Revert if already pushed

git revert HEAD

Example:

git push origin main

Common mistakes / Pitfalls

  • Using reset --hard without backup deletes uncommitted work.
  • Amending pushed commits requires force push and team coordination.
  • Confusing revert with reset can produce unexpected extra commits.
Last updated: February 2026