Question

Changing a git commit message

  • Posted on November 10, 2020
  • Git
  • alexdoAsked by alexdo

I recently got asked if there is a way to change the commit message we just entered in git.

If a commit message contains unclear, incorrect, or sensitive information, you can amend it locally and push a new commit with a new message to GitHub. You can also change a commit message to add missing information.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
November 10, 2020
Accepted Answer

Hello,

I will recommend everyone to navigate to github official docs and change the following article:

https://docs.github.com/en/free-pro-team@latest/github/committing-changes-to-your-project/changing-a-commit-message

There are several cases which are all covered in the official document page.

An example is to amend a message that has not been pushed online yet. You need to navigate to you local repository that contains the commit you want to change. In your terminal client type the following command:

git commit --amend

You can now edit the commit message in the text editor and save the commit.

The other scenario is to edit the most recent commit message. You can achieve that using the exact same command:

git commit --amend

Changing the commit message will create a new commit to replace the old one.

Hope that this helps! Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel