To edit the commit messages of a series of commits, I run
git rebase -i firstsha
firstsha is an identifier for the parent commit of the first commit I want to edit. (You can use any valid reference here, so
git rebase -i HEAD~4 will show the last four commits.)
In the editor that opens, change all the “pick” entries to “reword” on commits you wish to modify, then close the editor; you will then be asked to enter commit messages for all the commits you chose.
Note that this will change the commit tree, because the hashes of the commits will change. You will have to force-push your new tree, or push it to a new branch. It will also mess up merges, so avoid editing merge commits.
To quickly edit only the last commit, run
git commit --amend
(but beware of anything staged for commit though).