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