Undo the last commit but keep my changes
I committed too early. I want the commit gone but my work kept.
The problem
I committed too early. I want the commit gone but my work kept.
How the practice repository looked before
## main
19fd99e Add line two 64396ec Add notes
The fix
Check the result
M notes.txt
64396ec Add notes
Why this works
--soft moves the branch back one commit and leaves your files and the staging area as they were, so the change from the undone commit is staged and ready to commit again. HEAD~1 means "one commit before the current one".
If this is not quite your case
After the reset, git status shows the file as staged. You can now change it, add other files, and make a better commit. To undo more than one commit, use HEAD~2, HEAD~3 and so on. If you want the changes unstaged as well, use git reset HEAD~1 (the mixed mode) instead; the page on reset modes compares all three.
Be careful: Only do this on commits you have not pushed. If you already pushed, use the revert page instead.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.