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
When doing git rebase -i
there is this interesting bit in the doc:
If you want to fold two or more commits into one, replace the command
"pick"
for the second and subsequent commits with"squash"
or"fixup"
. If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit message for the folded commit is the concatenation of the commit messages of the first commit and of those with the"squash"
command, but omits the commit messages of commits with the"fixup"
command.
A-B-C-D-E-F
,B
and D
(= 2 commits),then you can do:
git config user.name "Correct new name"
git config user.email "correct@new.email"
git commit --allow-empty -m "empty"
git rebase -i B^
B^
selects the parent of B
.pick
to squash
for those.Example of what git rebase -i B^
will give you:
pick sha-commit-B some message
pick sha-commit-C some message
pick sha-commit-D some message
pick sha-commit-E some message
pick sha-commit-F some message
# pick sha-commit-empty1 empty
# pick sha-commit-empty2 empty
change that to:
# change commit B's author
pick sha-commit-empty1 empty
squash sha-commit-B some message
# leave commit C alone
pick sha-commit-C some message
# change commit D's author
pick sha-commit-empty2 empty
squash sha-commit-D some message
# leave commit E-F alone
pick sha-commit-E some message
pick sha-commit-F some message
It will prompt you to edit the messages:
# This is a combination of 2 commits.
# The first commit's message is:
empty
# This is the 2nd commit message:
...some useful commit message there...
and you can just remove the first few lines.