How to change the commit message in git

Today we’ll show you how to change the commit message in git. This is a small article but very useful for those who work with git.

change commit message after pushed on remote, change the last commit message, change the pushed commit message, change the previous commit message in git, change the multiple commit messages in git, edit the commit message in github, How To Amend Git Commit Message, How can I edit / fix the last commit’s message?, How to modify existing, unpushed commit messages?

In this article, we’ll show you both cases where you might need to change the commit message in git history.

To change commit message in git

  1. Change unpushed commit message
  2. Change commit message that already pushed
  3. Change more than one commit messages

1. Change unpushed commit message

Let’s assume that you have committed the code but it’s not pushed yet. In this type of case, you can change the most recent commit message by running the command below.

After executing the command, Editor will be auto open where you can change the commit message then save and close it.

You can also change the commit message directly in the command line.

2. Change commit message that already pushed

If you have already pushed your code to git remote branch then first execute above command and follow the command below to forcefully push the commit message.

OR

3. Change more than one commit messages

To change more than one commit message, We need to use rebase command as mentioned below.

Use the number of commits instead of <commit_count> in the above command like git rebase -i HEAD~2. This will launch the editor where you have to replace the word pick to reword. Check below code for your understanding.

Before

After

Now save and close the editor. At a time another editor will be open where you can update the commit message. The editor will open as many times as you have passed the number in <commit_count>.

Run the below command to push the commit on remote branch.

OR

That’s it for today.
Thank you for reading. Happy Coding!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *