reword commit message in git

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:

Git Rebase Example
Example of a git rebase for rewording a commit message. NOTE: I am using vim here, but your default editor should come up.

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:

Git Reword Commit Example
Example of a Git Commit Reword editor. Here, you’d change the commit message to reflect whatever changes happened for the commit.

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.