This article will elaborate on how to change the author of a commit.
How to Change the Author of Single Commit?
Git users can set and change the author of commits. We have listed down the methods to change the author of a single commit:
- How to Change the Author of a Recent Commit?
- How to Change Author for a Single Commit From Commit History?
How to Change the Author of a Recent Commit?
To change the author of a recent commit, first, open the Git repository and then utilize the “git commit” command along with the “–amend –author” options.
Utilize the mentioned command to change the author of the recent commit.
Step 1: Open Git Bash Terminal
Launch the Git Bash terminal from the Startup menu:
Step 2: Go to Git Repository
Use the “cd” command and go to the required Git local repository:
Step 3: Check Git Log
Check out the Git logs to view the author name of the latest commit:
Step 4: Change Author of Recent Commit
Change the author of the latest commit through the “git commit” command. The “–amend” option is used to modify the commit, and the “–author” is used to edit the author information:
As a result, the “COMMIT_EDITMSG” file will open in the default selected text editor, specify your message according to your preferences and hit the “CTRL” key to save the commit message:
Step 5: Check Git Log
Again, check the Git logs to verify if the author of the latest commit is changed or not:
The below output indicates that we have successfully changed the author of a recent commit:
How to Change Author for a Single Commit From Commit History?
In order to change the author for a single commit from the commit history, follow the mentioned procedure.
Step 1: Check Git Logs
First, open the Git logs to check the Git commits by utilizing the “git log” command:
Step 2: Change the Author of Old Commit
Next, change the author of any old commit from history by utilizing the Git “rebase” command. Also, specify the “HEAD” pointer position to move to that commit:
Upon doing so, the “git-rebase-todo” file will open. To change the commit author, use the highlighted command below, along with the author’s name and email address, and then press “CTRL+S” to save changes:
Step 3: Check Git Commits
Finally, view the commit history for verification:
Here, you can see we have successfully changed the author of the older commit:
We have taught you how to change the author for a single commit.
Conclusion
To change the author of a single commit, Git users can utilize two approaches. In the first approach, git users can change the author of a recent commit by utilizing the “git commit –amend –author author-name <email>” command. To change the author of an older commit, utilize the “git rebase HEAD~<position>” command. Then, set the author’s name and email address in the opened file. This article has elaborated on how to change the author for a single commit.