Modify an existing unpushed commit message in Git

David Y.

The Problem

In Git, how do I modify the commit message for a commit I’ve made but not yet pushed to a remote?

The Solution

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."
Join the discussionCome work with us
Share on Twitter
Bookmark this page
Ask a questionImprove this Answer

Related Answers

A better experience for your users. An easier life for your developers.

© 2023 • Sentry is a registered Trademark
of Functional Software, Inc.