git reset --mixed HEAD~1

Undo last commit, keep changes staged

This command starts by undoing the last commit, effectively moving the current HEAD to the specified HEAD~1, meaning the previous commit.

The --mixed flag is used to reset the index (staging area) but not the working directory, thereby preserving the changes from the commit in the working directory but un-staging them.

Variants of this command include using --soft to retain the commit changes in the index as well, and --hard to remove the changes from both the index and working directory. For example, git reset --soft HEAD~1 leaves changes staged, while git reset --hard HEAD~1 discards all changes.

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