_thg9a
Last Updated: August 20, 2017
·
21.84K
· garethrees
E481eca839bcb4b4ed39438e0a485de8

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.

Say Thanks
Respond

2 Responses
Add your response

3887
99171db5dee1e3ab645e9a32168596af

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 ·
3888
6704306c30c932e916c6030c0314a415

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

over 1 year ago ·
Filed Under