Every once in a while, I’ll make a mistake in my Git commit message and will need to go back and fix it. You would think rewording your message would be more intuitive, but nay.
Assuming your most recent commit was the problem (otherwise you would change the number to indicate how far back the commit goes):
git rebase -i HEAD~1
You’ll see something similar to the following:
The next thing you would do is change the word pick to the word reword or even r would work, and touch nothing else. Save and exit.
Again you’ll be presented with your editor screen, this time with the commit message to be changed:
Update the commit message here, then save and exit.
That’s it for a local repo. If you’ve already pushed this upstream, you’ll have to force push your changes or the remote repo will reject them:
git push origin [branch-name-here] --force
And that should be it. Of course, you should always be extremely careful when rebasing and then force-pushing to origin as you can easily overwrite new changes, and wipe out proper git commit history.