gpt4 book ai didi

git log 未按时间顺序排列

转载 作者:IT王子 更新时间:2023-10-29 01:01:00 28 4
gpt4 key购买 nike

我在一个公共(public)项目(B2G aka 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

提前致谢。

编辑:真正的问题是:提交 (d4bb883) 的提交日期怎么可能比其直接父级 (5f3a596) 的提交日期早?由于 --graph 选项,我可以断言它是直接父级。

最佳答案

来自 the documentation for git log :

--graph

Draw a text-based graphical representation of the commit history on the left hand side of the output. This may cause extra lines to be printed in between commits, in order for the graph history to be drawn properly.

[...]

This implies the --topo-order option by default, but the --date-order option may also be specified.

如果我们查看--topo-order 选项的文档:

--topo-order

Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.

For example, in a commit history like this:

---1----2----4----7
\ \
3----5----6----8---

where the numbers denote the order of commit timestamps, git rev-list and friends with --date-order show the commits in the timestamp order: 8 7 6 5 4 3 2 1.

With --topo-order, they would show 8 6 5 3 7 4 2 1 (or 8 7 4 2 6 5 3 1); some older commits are shown before newer ones in order to avoid showing the commits from two parallel development track mixed together.

因此,因为您将 git log 与 --graph 一起使用,所以较新的提交总是排在其子项之下。因此,如果您有一个较旧的提交,它是较新提交的子提交,git log --graph 将在较新的提交之上显示较旧的提交。

这怎么可能发生呢?提交 (d4bb883) 的提交日期怎么可能比其直接父项的提交日期早? parent 不必先 promise 吗?好吧,提交时间戳只是 git 添加到提交的元数据,并且由于 git 的分布式特性,没有什么可以阻止提交者在他们创建的提交上设置他们想要的任何日期。事实上,git rebase甚至有明确允许您“谎报”提交日期的选项:

--committer-date-is-author-date

--ignore-date

These flags are passed to git am to easily change the dates of the rebased commits (see git-am[1]).

git-am's docs说:

--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.

不过,除了 --committer-date-is-author-date 之外,还有其他方式可以错误地设置提交日期,例如在提交者的 PC 上错误地设置系统时钟.关键是,提交者日期不一定总是准确的。

关于git log 未按时间顺序排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036387/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com