Is there a way to edit a commit message on GitHub?
-
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
. -
For any commit you wish to change the message, change
pick
toreword
. -
Save and quit (in vi:
:wq
). -
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
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:
-
git reset --soft b7ec061
will keep your changes of files and reset to parent-commit (i.e. b7ec061) -
git commit -m "..."
will locally create a new commit -
git push -f
will push your new commit to the server and replace the old one (i.e. df9c192)