How can I edit my last commit message?

You may find you've just created a new commit, but you want to modify the message.

Simply navigate to your project's directory via the command prompt, and use the git commit amend flag:

$ git commit --amend

You'll be redirected to your text editor to edit the message. The message will be at the very top of the screen; simply edit it:

New commit message

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Thu May 16 11:47:16 2019 +0100
#
# On branch my_new_branch
# Your branch is up to date with 'origin/my_new_branch'.
#
# Changes to be committed:
#       new file:   newfile
#

Then, press ctrl + x followed by y and the enter key.

[my_new_branch b356ae0] New commit message
 Date: Thu May 16 11:47:16 2019 +0100
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 newfile

Note that --amend rewrites history. If you've already pushed the commit, you'll need to force-push with git push --force-with-lease to update the remote.

You can use git log to verify the message was updated correctly. If you need to update the author across multiple commits instead, see how to update the author of multiple commits.

Ready to streamline your Git workflow? DeployHQ deploys your code automatically whenever you push to your repository.