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.