Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git

How to change the most recent commit message

Syed Muhammad Ali Mustafa

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

git commit -m "file1.txt removed"

git commit --amend -m "file1.txt deleted from working directory"

Explanation

  • The code snippet above removes the file file1.txt from the working directory using rm command. We save the changes in the removed file to the local repository using the git commit with option -m in line 3.
  • We use the git commit command with the amend option in line 5 to change the commit message.

RELATED TAGS

git

CONTRIBUTOR

Syed Muhammad Ali Mustafa
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring