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."

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

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

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