git reset --soft HEAD~1

Undo last commit, keep changes staged.

This command is useful for undoing the last commit while keeping the changes staged, allowing you to amend the commit or make additional changes before committing again.

It operates by moving the HEAD pointer back by one commit without altering the index or working directory, effectively uncommitting the last commit but preserving the changes in the staging area.

The --soft flag ensures that the changes from the last commit remain staged, making it easy to modify the commit message or add more changes before recommitting. This is particularly useful when you realize a mistake in the commit message or need to include additional changes.

Variations of this command include git reset --mixed HEAD~1, which unstages the changes but keeps them in the working directory, and git reset --hard HEAD~1, which discards all changes. For similar purposes, git commit --amend can be used to modify the last commit without changing the commit history, and git revert HEAD can be used to create a new commit that undoes the changes of the last commit.

Sign in to enable bookmarking, reminders, progress-tracking and more...