How to Modify Existing, Unpushed Commit Messages?

Better Stack Team
Updated on June 24, 2024

To modify existing, unpushed commit messages in Git, you can use the git commit --amend command. Here's how you can do it:

Step 1: Make Your Changes

First, make sure you're in the branch containing the commit message you want to modify. Then, make the desired changes to your files.

Step 2: Amend the Last Commit

Once you've made your changes, use the following command to amend the last commit:

 
git commit --amend

This will open your default text editor, allowing you to modify the commit message. You can make your changes to the message, save, and close the editor.

Step 3: Push the Changes (If Necessary)

If you've already pushed the original commit to a remote repository, keep in mind that you've rewritten the commit history by amending the commit message. In this case, you'll need to force-push the changes to update the remote repository:

 
git push --force

Note:

  • Be cautious when amending commit messages, especially if you've already shared the commit with others. Rewriting commit history can cause issues for collaborators who have already pulled the original commits.
  • If you've made changes to the commit other than just the message, those changes will also be included in the amended commit.
  • If you want to change a commit message that's not the most recent one, you can use interactive rebase (git rebase -i) to modify older commits.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github