2014年6月更新:David Fraser在评论中提到了一种解决方案,也在“更改重新基础git分支的时间戳”中进行了详细介绍,使用选项--committer-date-is-author-date
(最初在提交3f01ad6中引入于2009年1月)。
Note that the --committer-date-is-author-date
option seems to leave the author timestamp, and set the committer timestamp to be the same as the original author timestamp, which is what the OP Olivier Verdier wanted.
I found the last commit with the correct date and did:
git rebase --committer-date-is-author-date SHA
参见 git am
:
--committer-date-is-author-date
By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date.
This allows the user to lie about the committer date by using the same value as the author date.
注意:从 Git 2.29 (2020 年第四季度) 开始,git rebase
--committer-date-is-author-date
或
--ignore-date
也适用于以下情况:
- 交互式 rebase (
rebase -i
/rebase --interactive
)
- 对于根提交 (
git rebase --root
)
请参见 "
在 rebase git 分支时更改时间戳"。
(原始回答,2012年6月)
你可以尝试使用非交互式的变基
(请参见上文:使用Git 2.29,2020年第4季度,这也适用于交互式变基)
git rebase --ignore-date
(来自这个SO答案)
这将传递给git am
,它提到:
--ignore-date
默认情况下,该命令将电子邮件中的日期记录为提交作者日期,并使用提交创建时间作为提交者日期。
这允许用户通过使用与提交者日期相同的值来欺骗作者日期。
对于
git rebase
,此选项与“--interactive”选项不兼容。
由于
您可以随意更改旧提交日期的时间戳(使用
git filter-branch
),我想您可以根据需要以任何提交日期顺序组织您的Git历史记录,甚至
将其设置为未来!。
正如Olivier在他的问题中提到的那样,作者日期永远不会因为变基而改变;
来自Pro Git Book:
- 作者是最初撰写该作品的人,
- 而提交者是最后应用该作品的人。
因此,如果您向项目发送补丁,并且核心成员之一应用了该补丁,则两个人都会获得信用。
为了更加清晰,在此情况下,正如Olivier所评论的:
--ignore-date
的作用与我想要实现的相反!
也就是说,它会删除作者的时间戳并用提交的时间戳替换它们!
因此,对我的问题的正确答案是:
不要做任何事情,因为git rebase
默认情况下实际上不会更改作者的时间戳。
正如DylanYoung在评论中所述,使用"如何在Git rebase期间通过哈希标识冲突提交?":
Using the SEQUENCE_EDITOR
variable and rebase interactive, you would just loop over the current todo
list and add a command setting the GIT_COMMITER_DATE
to the date of the original commit before each commit in the todo
.
It's a bit less fiddly because you have the list of original commits to start with (you don't have to hack into git internals to find it), but a bit more work because you have to handle the entire list at once. –
Once you're able to identify the original commit you can do something like:
git rebase -x 'GIT_COMMITTER_DATE="git show -s --format=%ci ``get_current_commit``" git commit --amend --no-edit
git rebase --committer-date-is-author-date SHA
。请参阅我下面编辑的答案。 - VonC