Is there a way to edit a commit message after committing and pushing to GitHub? I see that there is a 'add a note' as well as inline commenting, but no actual editing of a commit message. There is also 'amend commit' in git extensions but that doesn't edit the existing message.
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
For any commit you wish to change the message, change
Save and quit (in vi:
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.
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.
- Open Version Control (History)
- Select log tab
- Select commit to change comment
- press F2 (Mac fn + F2), and update your commit message
Another option is to create an additional "errata commit" (and push) which references the commit object that contains the error -- the new errata commit also provides the correction. An errata commit is a commit with no substantive code changes but an important commit message -- for example, add one space character to your readme file and commit that change with the important commit message, or use the git option
--allow-empty. It's certainly easier and safer than rebasing, it doesn't modify true history, and it keeps the branch tree clean (using
amend is also a good choice if you are correcting the most recent commit, but an errata commit may be a good choice for older commits). This type of thing so rarely happens that simply documenting the mistake is good enough. In the future, if you need to search through a git log for a feature keyword, the original (erroneous) commit may not appear because the wrong keyword was used in that original commit (the original typo) -- however, the keyword will appear in the errata commit which will then point you to the original commit that had the typo. Here's an example:
$ git log commit 0c28141c68adae276840f17ccd4766542c33cf1d Author: First Last Date: Wed Aug 8 15:55:52 2018 -0600 Errata commit: This commit has no substantive code change. THis commit is provided only to document a correction to a previous commit message. This pertains to commit object e083a7abd8deb5776cb304fa13731a4182a24be1 Original incorrect commit message: Changed background color to red Correction (*change highlighted*): Changed background color to *blue* commit 032d0ff0601bff79bdef3c6f0a02ebfa061c4ad4 Author: First Last Date: Wed Aug 8 15:43:16 2018 -0600 Some interim commit message commit e083a7abd8deb5776cb304fa13731a4182a24be1 Author: First Last Date: Wed Aug 8 13:31:32 2018 -0600 Changed background color to red
if your git-graph looks like ...
O target-commit that you want to change its message [df9c192] | O parent-commit [b7ec061] | O
b7ec061 are the commit hashes of target-commit and parent-commit, separately)
you can just type the following instructions...
git reset --soft b7ec061 git commit -m "your_new_description" git push -f
git reset --soft b7ec061will keep your changes of files and reset to parent-commit (i.e. b7ec061)
git commit -m "..."will locally create a new commit
git push -fwill push your new commit to the server and replace the old one (i.e. df9c192)