CommandGit

Undo the last commit, keep changes

Removes the last commit but leaves every changed file staged, ready to re-commit with a different message or split into separate commits.

Last updated

Commandgit
git reset --soft HEAD~1

How it works

git reset moves the current branch pointer; --soft is the mode that moves it WITHOUT touching the index or the working tree, so every file changed by that commit reappears exactly as it was — staged and ready to commit again. HEAD~1 means "the commit one before HEAD", i.e. undo just the most recent commit.

This is the recipe for the common "I committed too early" moment: fix a typo in the message, split the commit into smaller ones, or add a forgotten file to the same change — all without losing any of the actual work.

Watch out for

  • Only do this to commits that are still local and unpushed. If the commit has already been pushed and someone else might have pulled it, rewriting history like this causes their branch to diverge from yours — use git revert for anything already shared.
  • --soft keeps changes staged; --mixed (the default reset mode, i.e. just git reset HEAD~1) keeps them but unstages them; --hard discards them entirely — picking the wrong mode by habit is a common way to lose work, so it's worth typing the flag explicitly every time.
  • HEAD~1 undoes exactly one commit; chain further back with HEAD~2, HEAD~3, or reset to a specific commit hash if you need to undo more than the last commit.

Related in Commands