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.

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

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.