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


当前回答

使用交互式rebase,您可以在每次提交后放置一个修改命令。例如:

pick a07cb86 Project tile template with full details and styling
x git commit --amend --reset-author -Chead

其他回答

当从另一位作者手中接过一份未合并的承诺时,有一种简单的方法来处理。

gitcommit--修改--重置作者

试试看。它将执行与上述相同的操作,但以交互方式执行。

bash <(curl -s  https://raw.githubusercontent.com/majdarbash/git-author-change-script/master/run.sh)

参考:https://github.com/majdarbash/git-author-change-script

更改最后N次提交的作者的单个命令:

git rebase -i HEAD~N -x "git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit"

笔记

用引用替换HEAD~N,直到您要重写提交的地方。这可以是哈希、HEAD~4、分支名称。。。--no edit标志确保gitcommit--modify不会要求额外的确认当您使用gitrebase-i时,您可以手动选择要更改作者的提交位置,

您编辑的文件将如下所示:

pick 897fe9e simplify code a little
exec git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit
pick abb60f9 add new feature
exec git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit
pick dc18f70 bugfix
exec git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit

然后,您仍然可以修改一些行,以查看要更改作者的位置。这为您在自动化和控制之间提供了一个很好的中间地带:您可以看到将要运行的步骤,一旦您保存了所有内容,将立即应用。

请注意,如果您已经使用git-configuser.name<your_name>和git-config user.email<your_email>修复了作者信息,那么也可以使用以下命令:

git rebase -i HEAD~N -x "git commit --amend --reset-author --no-edit"

使用交互式rebase,您可以在每次提交后放置一个修改命令。例如:

pick a07cb86 Project tile template with full details and styling
x git commit --amend --reset-author -Chead

如果您是此回购协议的唯一用户,或者您不关心其他用户是否可能破坏回购协议,那么可以。如果你已经推送了这些提交,并且它们存在于其他地方可以访问它们,那么就不会,除非你不在乎破坏他人的转发。问题是通过更改这些提交,您将生成新的SHA,这将导致它们被视为不同的提交。当其他人试图加入这些更改的提交时,历史是不同的,令人兴奋。

本页http://inputvalidation.blogspot.com/2008/08/how-to-change-git-commit-author.html描述了如何做到这一点。(我还没有尝试过,所以YMMV)