Accidentally pushed commit: change git commit message
Solution 1:
Easiest solution (but please read this whole answer before doing this):
git rebase -i <hash-of-commit-preceding-the-incorrect-one>
- In the editor that opens, change
pick
toreword
on the line for the incorrect commit. - Save the file and close the editor.
- The editor will open again with the incorrect commit message. Fix it.
- Save the file and close the editor.
-
git push --force
to update GitHub.
This will mean you will be publishing a modified version of a previously published repository. If anyone pulled or fetched from your repo between when you made the mistake with the incorrect commit message, and when you fixed it, then they will experience some difficulties later. So be sure you can accept this consequence before trying this.
Solution 2:
Rather than go the whole rebase route for one commit:
git reset --soft head~
git commit -m "The message you wanted to use"
git push -f
You can see the options in the git-reset manpage.
For a project that only you are working on, the changed history shouldn't be a problem.