How to edit an incorrect commit message in Git?

Update: This article was originally published in 2013. As you know, the web is constantly changing, which means some of the advice on this page may become out of date. For the latest digital marketing insights from the RocketMill team, please visit our main blog page.

So, you have pushed an incorrect commit message?

Let’s admit it we have all pushed a bad or incorrect commit message, it happens to the best of us.

Try the following:

git commit --amend -m &quot;New commit message&quot;

That command should be used whenever you want to amend the tip of the current branch. The commit you create replaces the current tip — if it was a merge, it will have the parents of the current tip as parents — so the current top commit is discarded. It is a rough equivalent for the following, but can be used to amend a merge commit.

Can I use this to edit the commit message on Github?

Nope. The command highlighted above does not work on Github website as this is not directly possible. The hash for every Git commit is also calculated based on the commit message. When you change the commit message, you change the commit hash. If you want to push that commit, you have to force that push (git push -f). But if already someone pulled your old commit and started a work based on that commit, he would have to rebase his work onto your new commit.