I want to change the author of one specific commit in the history. It's not the last commit.
I know about this question - How do I change the author of a commit in git?
But I am thinking about something, where I identify the commit by hash or short-hash.
Interactive rebase off of a point earlier in the history than the commit you need to modify (
git rebase -i <earliercommit>
). In the list of commits being rebased, change the text frompick
toedit
next to the hash of the one you want to modify. Then when git prompts you to change the commit, use this:For example, if your commit history is
A-B-C-D-E-F
withF
asHEAD
, and you want to change the author ofC
andD
, then you would...git rebase -i B
(here is an example of what you will see after executing thegit rebase -i B
command)A
, usegit rebase -i --root
C
andD
frompick
toedit
C
git commit --amend --author="Author Name <email@address.com>"
git rebase --continue
D
git commit --amend --author="Author Name <email@address.com>"
againgit rebase --continue
git push -f
to update your origin with the updated commits.Github documentation contains a script that replaces the committer info for all commits in a branch.
Commit before:
To fix author for all commits you can apply command from @Amber's answer:
Or to reuse your name and email you can just write:
Commit after the command:
For example to change all starting from
4025621
:You must run:
Note: To include an author containing spaces such as a name and email address, the author must be surrounded by escaped quotes. For example:
or add this alias into
~/.gitconfig
:And then run: