In Git, changing the author of a commit can help to maintain accurate and consistent records of code changes, protect privacy, and open-source guidelines. However, it is important to utilize this feature only when necessary, as modifying the author’s information can alter the historical record of a codebase.
This tutorial will elaborate on the easiest method for modifying the Git commit author.
What is Git Commit Author?
The commit author is the person who created a particular commit in Git. When users create a commit in Git, its records information about the author and the changes that were made to the codebase. The commit author is typically identified by their name and email address, which are recorded as part of the commit metadata. This information is used to keep track of who made each commit and to provide context and accountability for the changes that were made.
How to Change Git Commit Author?
To change Git commit author, provided command can be used:
To do so, follow the below-stated procedure:
- Move to the Git root directory.
- Display complete Git history.
- To change the commit author, use the above-stated command.
- Verify the changes by checking the Git log history.
Step 1: Go to the Git Local Directory
Initially, execute the “cd” command and navigate to the below-stated repository:
Step 2: Show Git Log
Run the “git log” command to display the complete commit history:
From the given output, we have selected the below-highlighted commit hash:
Step 3: Modify the Author
Utilize the “git commit” command with the “–amend –author” option to change the commit author by specifying the username and email id:
As a result, the editable file will be opened with the default editor. Add author name and email id. Then, Modify the commit message, save changes, and close it:
The below-provided output indicates that the particular commit has been modified successfully:
Step 4: Verification
To verify the modified commit author name and id, use the below-given command:
It can be observed that the author’s name and email have been modified successfully:
That’s all about the Git commits author and the method for modifying it.
Conclusion
To change Git commit author, first, go to the Git root directory and show the complete Git history using the “git log”. Then, modify the author “git commit –amend –author “author name <[email protected]>“. Lastly, verify the committed author by checking the Git log history. This blog post has stated about the Git commit author and the method for modifying it.