How To Fix Git Commit Messages
Every once in a while, I’ll make a mistake in my Git commit message and I 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~1You’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] --forceAnd 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.
Update:
Recently, I ran into an issue while trying to reword a commit where Git threw the following error:
error: gpg failed to sign the data
fatal: failed to write commit objectTurns out Git was attempting to sign my commits, but my GPG key wasn’t configured correctly. If you run into the same thing, you can temporarily bypass it with:
git config --global commit.gpgsign falseOr, if you want to properly set up GPG signing (or even retroactively sign old commits), I highly recommend checking out this excellent guide:

