In this study, we will explain the method to amend Git commit messages.
How to Amend a Git Commit Message?
To amend a Git commit message, first, we will move to the Git root folder and create a new Git directory. Then, create and add a new file into the directory and commit changes. After that, we will execute the “$ git commit –amend -m <“new-message”>” command to change the most recent commit message.
Now, check out the below-mentioned steps to modify a recent commit message!
Step 1: Move to Git Root Folder
First, navigate to the Git root folder through the “cd” command:
Step 2: Create New Directory
Next, create a new directory using the provided command:
Step 3: Move to Created Directory
Now, run the “cd” command to move to the recently created directory:
Step 4: Create and Update File
To create and update a file, run the “echo” command:
Step 5: Update Directory
Next, update the directory and track the file by executing provided command:
Step 6: Commit Changes
Now, commit all changes with the required message to the Git repository:
Step 7: View Log History
After that, use the “git log” command with the “–oneline” option to view the Git repository reference log history:
As you see, the HEAD points to the most recently added commit:
Step 8: Amend Git Commit
Finally, execute the below command to amend the most recent added commit message:
Below output shows that the previously committed message is replaced with the new message:
Step 9: Verify Amend Git Commit
Lastly, execute the “git log” command to ensure that the commit message is replaced or not:
It can be seen that we have successfully amended the recent commit message:
We have offered the procedure to amend a Git commit message
Conclusion
To amend a Git commit message, first, navigate to the Git root folder and create a new Git directory. Then create a new file and add it to the Git repository. After that, commit changes by executing the “$ git commit -m <commit-message>”. Lastly, update the commit message using the “$ git commit –amend -m <new-message>” command. This study illustrated how to amend Git commit messages.