If you’re like me, on more than one occasion you’ve typed out your commit message and noticed a nasty typo after the fact.
Here’s a quick way to amend your last commit message if you have already entered your commit message in the terminal but have not yet pushed your local branch to the remote branch.
$ git commit --amend
This will open up your editor to edit your commit message. But if your prefer to do it all on one line in your terminal, you can type it in directly like this:
$ git commit --amend -m "Type your new commit message"
Remember, this method works only on your most recent commit and only if it has not yet pushed up to its remote branch.