How to update git commit messages (single or multiple, local or remote)

Whether you want to update a single or multiple, local or remote git commit messages, this post shows you how.

To update the most recent local commit message

$ git commit --amend

The text editor opens, edit your commit message, save and close file.

To update multiple local commit messages

$ git rebase -i HEAD~3 # Modify the last 3 commits

You will see something like the following

pick e499d89 Delete CNAME
pick 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.
# … with some instructions in the comments here …

Replace pick with reword then save and close file.

Git will open the first commit above in the text editor, you can type the new commit message, save and close the file. Then git will open the second commit in the text editor, so on and so forth till you update, save and close the last commit file.

To update commits that have been pushed

Do exactly as explained above whether its the last one commit or last several commits. Then do this

$ git push --force

One thing to note is that the commit hashes will be updated as well.

Reference: Changing a commit message

© 2018 - Fanray

Powered by Fanray