How to edit an incorrect commit message in Git [#git]

This was a new one on me… and I needed it recently. I accidentally committed a change with a totally nonsensical message since I accidentally copy-and-pasted some code into the message field of my commit, which automatically commenced.

Thankfully, there is a way to update it before you push (that seems to be the key to success here… don’t push it after you do the commit with the bogus message):

version control – How do I edit an incorrect commit message in Git? – Stack Overflow

git commit --amend -m "New commit message"

I’m just relieved that this can be done… and a little surprised — given how grumpy and curmudgeonly Git feels sometimes.