How to edit a commit message on GitHub?

I made a mistake while writing the commit message. Is there a way to change the message? The commit has not been pushed yet.

Comments

I had the Same problems a couple of times… Thanks for summing it up this way, together with all the Provided solutions this helps a lot.
Moritz Ruoff Holzer - Wed, 12/22/2021 - 07:40 :::
4 answers

I found a simple soloution!

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

Taggings:

My approach to edditing a commit message is to do an interactive rebase with the command git rebase -i HEAD~3.

This allows to change all commit until the specified commit (in this case 3 commits behind head, you can also give the SHA-1 hash of a commit instead of a number behind HEAD.

Afterwards, notepad opens where the commits are shown in order. There you can edit all commit messages as well as squash commits into the previous.

A more detailed description can be found here [1]

https://www.sitepoint.com/git-interactive-rebase-guide/

I would go with the --amend command, just remember that you then need to force that push (-f). So if someone already pulled your old commit they would have to rebase their work onto your new commit, but if you are only changing the message it's really not a problem but good to keep in mind.

Comments

I would also do it with the --amend command

Nino Ziegelwanger - Wed, 12/22/2021 - 10:39 :::

Hi, I had this problem already a few times, a good source for IntelliJ is: https://www.jetbrains.com/help/idea/edit-project-history.html#reword-commit
Even after pushing the commit, it is possible to change the message.
If you have not pushed yet this is a solution (for IntelliJ):

• Right-click the commit whose message you want to edit in the Log tab of the Git tool window Alt+9 and select Edit Commit Message from the context menu, or press F2.

• In the dialog that opens, enter a new commit message and click OK

You can also use the "git commit --amend" command.

I hope this helps!