Last Updated: November 19, 2020
·
74.57K
· garethrees

Reword a git commit message

Lets say you made a typo in a commit

$ git commit -am 'Fx the bugz'

Oh noes! You made a typo.

$ git commit --amend

This will open your commit editor. You can simply reword the message and you're done.

But what if you only noticed the bad message after you've made several commits?

Firstly, find out how far back the commit was:

$ git log

Lets say it was 3 commits ago.

$ git rebase HEAD~3 -i

You can now see the last 3 commits.

Find the commit with the bad commit message and change pick to reword.

You can now edit the message with your editor and git will update the commits.

Note: This rewrites history, so if you've previously pushed to a remote with this branch you'll need to --force push the new commits.

Related protips:

Force a "git stash pop"

2 Responses
Add your response

I instead find the SHA for the commit i want to edit and then:

git rebase -i sha^

It's a bit easier than counting how many commits back to go!

over 1 year ago ·

You can also save having to open the text editor by doing git commit -m "New message" --amend

over 1 year ago ·