我在一个公共项目(B2G 又名 FirefosOS)上意外发现 git log 输出不是按时间顺序排列的:
$ git clone https://git.mozilla.org/releases/gecko.git
$ git log --graph --format='%C(yellow)%h%Creset %cr %C(blue)%<(7,trunc)%cn%Creset -%C(auto)%d%Creset %<(80,trunc)%s' --all
* da7ef8a 74 minutes ago B2G B.. - (origin/v2.1) Bumping manifests a=b2g-bump
* ccf235d 83 minutes ago B2G B.. - Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
* 653f117 7 hours ago B2G B.. - Bumping manifests a=b2g-bump
* cc5501b 7 hours ago B2G B.. - Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
* b4a22de 13 hours ago B2G B.. - Bumping manifests a=b2g-bump
* 4ad0ee9 13 hours ago B2G B.. - Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
* 6390e1b 14 hours ago B2G B.. - Bumping manifests a=b2g-bump
* 9c57530 14 hours ago B2G B.. - Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
* 07e2a96 3 weeks ago Hsin-.. - Bug 1096128 - [B2G][STK] support call number modified by STK call control. r=a..
* 49daf73 3 weeks ago Fredr.. - Bug 1091601 - Settings closes down when changing permissions for THA applicati..
* d4bb883 3 weeks ago Rober.. - Bug 1073252. Fix bustage in part 4, a=bajaj
* 5f3a596 2 days ago B2G B.. - Bumping manifests a=b2g-bump
* 79bdd97 2 days ago B2G B.. - Bumping gaia.json for 1 gaia revision(s)
较旧的提交怎么可能位于最近的提交之前?
此行为也可以在 Web 界面上观察到:https://git.mozilla.org/?p=releases/gecko.git;a=log;h=refs/heads/master https://git.mozilla.org/?p=releases/gecko.git;a=log;h=refs/heads/master
提前致谢。
编辑:真正的问题是:提交(d4bb883)的提交日期怎么可能比其直接父级(5f3a596)更早?由于 --graph 选项,我可以断言它是直接父级。
From git log 的文档 http://git-scm.com/docs/git-log:
--graph
在输出的左侧绘制提交历史记录的基于文本的图形表示。这可能会导致在提交之间打印额外的行,以便正确绘制图形历史记录。
[...]
这意味着默认情况下 --topo-order 选项,但也可以指定 --date-order 选项。
如果我们查看文档--topo-order
option:
--拓扑顺序
在显示所有子项之前不显示父项,并避免显示混合的多行历史记录上的提交。
例如,在这样的提交历史记录中:
---1----2----4----7
\ \
3----5----6----8---
其中数字表示提交时间戳的顺序,git rev-list
和朋友--date-order
按时间戳顺序显示提交:8 7 6 5 4 3 2 1。
With --topo-order
,他们会显示 8 6 5 3 7 4 2 1 (或 8 7 4 2 6 5 3 1);一些较旧的提交显示在较新的提交之前,以避免显示来自两个并行开发轨道的提交混合在一起。
因为你正在使用 git log--graph
,较新的提交总是排序在其子项之下。因此,如果您有一个较旧的提交,它是较新提交的子项,那么它git log --graph
将在新提交上方显示较旧的提交。
但这怎么可能发生呢?提交 (d4bb883) 的提交日期怎么可能比其直接父级更早?难道父母不需要先做出承诺吗?好吧,提交时间戳只是 git 添加到提交中的元数据,并且由于 git 的分布式特性,没有什么可以阻止提交者在他们创建的提交上设置他们想要的任何日期。实际上,git 变基 http://git-scm.com/docs/git-rebase甚至有明确允许您“撒谎”提交日期的选项:
--提交者日期是作者日期
--忽略日期
这些标志被传递给 git am 来轻松更改重新调整的提交的日期(请参阅git-am[1] http://git-scm.com/docs/git-am).
And git-am's docs http://git-scm.com/docs/git-am say:
--提交者日期是作者日期
默认情况下,该命令将电子邮件中的日期记录为提交作者日期,并使用提交创建时间作为提交者日期。这允许用户通过使用与作者日期相同的值来谎报提交者日期。
除了--committer-date-is-author-date
不过,还有其他可能导致错误设置提交日期的方式,例如提交者 PC 上的系统时钟设置不正确。关键是,提交者日期不一定总是准确的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)