You may find yourself in a situation where you've committed to the wrong branch or, for any reason, need to undo your last commit.
git reset --soft HEAD^1
The command undoes the last commit you made but keeps all the changes from that commit intact. Your files and changes remain in place and are still staged, ready to be committed again.
In other words, this is the right action when you want to undo the last commit without losing your changes—perhaps to rethink the commit message, add something else, or commit to a different branch.
Note that this command won’t help if the commit has already been pushed to a remote server.