我已经知道如何更改提交的作者(作者和提交者字段)。
git rebase --root --exec "git commit --amend --reset-author --no-edit"
但是当作者更改时,日期(作者日期和提交日期)会改变为当前日期。我该如何同时保存旧日期并更改作者?
我在这里回答了。简而言之:
git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase -f <commit/branch before wrong author and email, or --root to rebase all>
git rebase --root --exec 'git commit --amend --author="My Name <myemail@domain.com>" --no-edit'
但可以通过使用 git rebase --committer-date-is-author-date --root
命令进行修复。相比之下,这个命令完全保留了所有日期的所需效果:git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase --root
- user14391097--reset-author
同时更新作者日期不同,您可以直接显式设置作者。git rebase --root --exec "git commit --amend --author=John --no-edit"
--author=
覆盖提交者。使用标准的 A U Thor 格式指定显式作者。否则,它被认为是一个模式,并用于搜索由该作者创建的现有提交(即 rev-list --all -i --author=)。然后将从找到的第一个提交中复制提交作者。
以上的答案都没有完全适合我, 我使用 git filter-repo 工具,并带有 --mailmap
选项。 安装 git 扩展后,请按照以下步骤进行操作:
Create a my_mailmap
file like this:
New Name <new-mail@address.com> Old Name <old-mail@address.com>
Run the following command in your repos root directory:
git filter-repo --mailmap my_mailmap
(I additionally also needed the --force
option)
但请注意,这将替换整个历史记录中的邮件地址和姓名,请确保您知道自己在做什么。您可以使用git show -s --format=fuller
单独确认提交者和提交时间:
Author: Author Name <mail@address.com>
AuthorDate: Wed Dec 30 10:27:44 2020 +0100
Commit: Commiter Name <mail@address.com>
CommitDate: Wed Dec 30 10:27:44 2020 +0100
git filter-repo
中使用--force
选项。运行过滤器后,它删除了我的远程源,所以我必须在git remote add origin ....
中添加它回来。要推送到我的现有存储库,我必须使用git push --force
,或者您可以创建一个新的空存储库并将其推送到其中。所有提交都已正确更新作者,并保留了提交日期。感谢@tidreyer! - VoidZA使用--ignore-date
标志或--committer-date-is-author-date
git rebase --ignore-date
$ git rebase --root --ignore-date --exec "git commit --amend --reset-author --no-edit"
,但出现了fatal: cannot combine am options with either interactive or merge options。 - JonyStack
--env-filter
。 - user3159253