This post summarizes how to update author info of Git commits.

For most recent commit

To change the author info of most recent commit, run

git commit --amend --author="author_name <author_email> --no-edit"

Note that the <> around the email. It is mandatory, otherwise, we see the following weird error:

fatal: No existing author found with ‘xxxx’

If the author has been set in .git/config, we can also simply run:

git commit --amend --reset-author --no-edit

For older commits

If we want to change the author info for multiple commits, we can use git rebase. For example, suppose we have this commit graph: A->B->C->D->E, we want to change the author of commit B and D. Here is the steps:

  • Run the rebase command, git rebase -i A
  • A vim window opens and you will see a list of commit hash for B, C, D, E, with pick before them.
  • Change pick to edit, before the commit hash for commit B and D.
  • Save and quit vim window :wq
  • Run git commit --amend --author="author_name <author-email>" --no-edit (this is for commit B)
  • Run git rebase --continue to continue the rebase
  • Run git commit --amend --author="author_name <author-email>" --no-edit (this time for commit D)
  • Run git rebase --continue to continue the rebase

The rebase process finishes.

For a range of commits

If you want to change the author info from an older commit, to the most recent commit, there is a more efficient/faster way than the previous method:

# Note that to also include the root commit, we need to add --root option
git rebase --interactive --exec "git commit --amend --reset-author --no-edit" {commit-ref}

We will a vim window like this:

pick xxx
exec git commit --amend --reset-author --no-edit
pick xxx
exec git commit --amend --reset-author --no-edit

Save the quit the window (:wq). The author info for these commits will be changed automatically.

Note that changing the commit author info will change the commit hash for this commit, and also commit hash after that specific commit. So your local commit will diverge with remote if you have pushed those commits to the remote repo.