Git

How to Add a Git Commit Message

Git commit is the changes saved in the Git local repository. More specifically, to make changes in the Git repository, programmers prefer to add sensible messages for adding the relevant commit history. Whenever developers or programmers need to modify or access Git changes, they can easily access them through a specific commit message.

This blog will illustrate how to add and modify a Git commit message.

How to Add a Git Commit Message?

Git commits message played a vital role in maintaining commits history. To add a Git Commit message, check out the below-given procedure.

Step 1: Open Git Bash Terminal
First, open the Git Bash terminal from the Windows β€œStartup” menu:

Step 2: Move Git Repository
Next, open the Git local repository through the β€œcd” command:

$ cd "C:\Git"

Step 3: Generate New File
Generate a new file by executing the β€œtouch” command:

$ touch File1.txt

Step 4: Add File to Staging Area
Next, add the newly created file to the staging environment:

$ git add File1.txt

After adding a file to staging, check out the repository state with the help of the β€œgit status” command:

$ git status

Here, you can see the file is added to the staging environment and is ready to commit:

Step 5: Commit Staged File
Commit the staged file by utilizing the β€œgit commit” command. To add a message along with the commit, use the β€œ-m” option and add your message in the double quotations:

$ git commit -m "File1 is commited"

For instance, we have added the β€œFile1 is commited” message:

Lastly, verify whether the commit message is added with a new commit or not:

$ git log

How to Modify Git Commit Message?

After adding a commit, the Git users can modify the commit message if some spelling mistake occurs or for any other purpose. To do so, we have provided some steps that are mentioned below.

Step 1: Modify Commit Message
To modify the Git commit message, utilize the β€œ–amend” option in the git commit command:

$ git commit --amend

Upon doing so, the default selected editor will open the β€œCOMMIT_EDITMSG” file or page where the users can edit the commit message. For this purpose, we have edited the latest commit message. After that, press the β€œCTRL+S” key to save changes:

Step 2: Check Git Log
Next, execute the β€œgit log” command to check Git local repository log and to verify whether the message is modified or not:

$ git log

The below output shows that the commit messages have been modified:

Here you go! You have learned how to add and modify the Git commit message.

Conclusion

To add a Git commit message, first, open the Git local repository. Then, create a new file to make a new commit in the Git repository and add it to a staging environment. Next, commit the newly created file and embed the message along with the commit using the β€œgit commit -m <Commit Message>” command. However, to modify the latest commit, you can utilize the β€œgit commit –amend” command. This tutorial taught you how to add and modify a Git commit message.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.