This post summarizes how to update author info of Git commits.
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-editIf 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:
git rebase -i Apick before them.pick to edit, before the commit hash for commit B and D.:wqgit commit --amend --author="author_name <author-email>" --no-edit (this is for commit B)git rebase --continue to continue the rebasegit commit --amend --author="author_name <author-email>" --no-edit (this time for commit D)git rebase --continue to continue the rebaseThe rebase process finishes.
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.
This post summarizes how to update author info of Git commits.
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-editIf 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:
git rebase -i Apick before them.pick to edit, before the commit hash for commit B and D.:wqgit commit --amend --author="author_name <author-email>" --no-edit (this is for commit B)git rebase --continue to continue the rebasegit commit --amend --author="author_name <author-email>" --no-edit (this time for commit D)git rebase --continue to continue the rebaseThe rebase process finishes.
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.