Changing the last commit with Git

If you just commited your changes to the Git repository, but you just now realized that the commit message is wrong or misspelled, there are a few options that Git gives you to undo your changes.

If you just want to change your wrong commit message, you can use the following command:

git commit --amend

The usual -m option can be added if you want to specify the correct message in place.

If it's not just the message that's wrong, but also the added files that should not have been in this commit, then you can run the following command:

git reset --soft HEAD^

You are now just before you ran commit, after you added the files. Make the necessary changes and commit again, this time with the correct message and the correct files added / removed.