如何更改一系列提交的作者?


当前回答

对于所有提交,我的解决方案:

git rebase -i --root -x "git commit --amend --author 'bedorlan <bedorlan@gmail.com>' --no-edit"

其他回答

当您没有初始化$HOME/.gitconfig时,就会发生这种情况。您可以将其修复为:

git config --global user.name "you name"
git config --global user.email you@domain.example
git commit --amend --reset-author

使用Git 1.7.5.4版进行测试。

注意,这只修复了最后一次提交。

对于单个提交:

git commit --amend --author="Author Name <email@address.example>"

(摘自阿斯梅勒的回答)

注意,git存储了两个不同的电子邮件地址,一个是提交人(提交更改的人),另一个是作者(编写更改的人员)。

提交者信息在大多数地方都不会显示,但您可以通过git-log-1--format=%cn,%ce(或使用show而不是log来指定特定的提交)看到它。

虽然更改上一次提交的作者与gitcommit一样简单--修改--author“作者名称”<email@example.com>“,没有一个liner或argument对提交者信息做同样的处理。

解决方案是(暂时或不)更改您的用户信息,然后修改提交,这将更新提交者到您的当前信息:

git config user.email my_other_email@example.com 
git commit --amend

对于所有提交,我的解决方案:

git rebase -i --root -x "git commit --amend --author 'bedorlan <bedorlan@gmail.com>' --no-edit"
git rebase -i YOUR_FIRTS_COMMIT_SHA^

while true; do git commit --amend --author="Name Surname <email@example.com>" --no-edit && git rebase --continue; done

在重基完成后按^C#(循环将继续更新上次提交)