In Git, how do I modify the commit message for a commit I’ve made but not yet pushed to a remote?
We can use git commit --amend
to edit the latest commit message. Running this command will open an editor containing the existing commit message. We can then change the message, save the file, and close the editor. Behind the scenes, Git will replace our existing commit with a new one containing all the same changes as well as the modified message.
If we don’t want to change the existing message in an editor, we can specify the -m
flag with a new message:
git commit --amend -m "Corrected commit message."