Is there a way to edit a commit message on GitHub?

  1. git rebase -i <commit hash you want to change>^

    This will open your default editor (usually vi) with a list of commits and actions for each one. By default, the action is pick.

  2. For any commit you wish to change the message, change pick to reword.

  3. Save and quit (in vi: :wq).

  4. For each such commit, you'll get an editor to edit the commit message. Change it as you see fit, save and quit.

    Once you're done editing all the commit messages, you'll return to the command prompt, and have a new tree with the updated messages.

  5. You can now upload them to github by using git push origin --force.

If you just need to fix your last commit, you can replace steps 1-4 with git commit --amend.


In Intellij Idea you can do it so easy.

  1. Open Version Control (History)
  2. Select log tab
  3. Select commit to change comment
  4. press F2 (Mac fn + F2), and update your commit message

Premise:

if your git-graph looks like ...

O   target-commit that you want to change its message [df9c192]
|
O   parent-commit [b7ec061]
|
O

(df9c192 and b7ec061 are the commit hashes of target-commit and parent-commit, separately)

Solution:

you can just type the following instructions...

git reset --soft b7ec061
git commit -m "your_new_description"
git push -f

Explanation:

  1. git reset --soft b7ec061 will keep your changes of files and reset to parent-commit (i.e. b7ec061)
  2. git commit -m "..." will locally create a new commit
  3. git push -f will push your new commit to the server and replace the old one (i.e. df9c192)