Change a Commit Message Before It Has Been Pushed

March 20, 2020

Amend the Most Recent Commit Message

The most recent commit’s message can be modified by using the commit --amend command.

Open an Editor to edit the commit message

git commit --amend

This will open up an editor with the previous commit message that you can edit to something else. Usually the editor will have comments about what will be committed, to what branch, and the date of the original commit.


> git commit --amend
Add NPM open package to home page

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Date:      Thu Mar 19 18:26:41 2020 -0700
# On branch master
# Your branch is up to date with 'origin/master'.
# Changes to be committed:
#       new file:   content/nano/npm/

Modify Commit message in the command line

git commit --amend -m "Updated message"

The -m command will directly set the commit message in the same way running git commit -m "message" directly sets the message when creating the commit.