Git

How to Change the Commit Author for a Single Commit

Git is a famous DevOps project management tool widely used for managing the source code of projects. It manages code versions through git repositories, branches, and time-to-time commit changes. Different developers work on projects and commit changes. However, sometimes, Git users want to change the author of all commits or the author of a specific commit.

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:

$ cd "C:\Git"

Step 3: Check Git Log

Check out the Git logs to view the author name of the latest commit:

$ git log

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:

$ git commit --amend --author "Jazzy <[email protected]>"

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:

$ git log

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:

$ git log

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:

$ git rebase -i HEAD~1

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:

exec git commit --amend --author="Jazzy <[email protected]>" -C HEAD

Step 3: Check Git Commits

Finally, view the commit history for verification:

$ git log

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.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.