How to change the most recent commit message
We can use the git commit command to save any changes we make to the local repository. We use the git commit command with the -m option to create a git commit with a message.
Creating a git commit with a message is a good practice that helps describe and share our changes with other developers.
Note: It is a good practice to keep the length of the “message” below 50 characters.
Changing the most recent commit message
To change the most recent commit message, use the git commit command with the --amend option as shown below:
git commit --amend -m "New message"
Code
Consider the code snippet below, where we create a git commit with a message.
git rm file1.txtgit commit -m "file1.txt removed"git commit --amend -m "file1.txt deleted from working directory"
Explanation
- The code snippet above removes the file
file1.txtfrom the working directory usingrmcommand. We save the changes in the removed file to the local repository using the git commit with option-min line 3. - We use the
git commitcommand with theamendoption in line 5 to change the commit message.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved