How It Works
The git reset --soft HEAD~1 command moves the HEAD pointer back by one commit without changing the index or working directory. This means that all the changes from the undone commit remain staged and ready to be recommitted. It’s particularly useful when you realize you need to modify a commit message or add more changes to the same commit.
Compared to other reset modes, --soft is the least destructive: it only changes the commit history pointer. --mixed would also unstage changes, and --hard would remove them entirely.
Tip: You can replace HEAD~1 with a specific commit hash to undo multiple commits at once, but always make sure you haven’t already pushed them to a shared branch, to avoid conflicts.