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."
- Syntax.fmListen to the Syntax Podcast (opens in a new tab)
- ResourcesWhat is Distributed Tracing (opens in a new tab)
- Listen to the Syntax Podcast (opens in a new tab)
![Syntax.fm logo]()
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODES
Considered “not bad” by 4 million developers and more than 150,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.
