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:
Step 3: Generate New File
Generate a new file by executing the “touch” command:
Step 4: Add File to Staging Area
Next, add the newly created file to the staging environment:
After adding a file to staging, check out the repository state with the help of the “git status” command:
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:
For instance, we have added the “File1 is commited” message:
Lastly, verify whether the commit message is added with a new commit or not:
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:
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:
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.