我有一个 git 存储库,其中包含居住在不同时区的不同作者所做的提交。
我想使用 git log
查看自纪元以来以秒为单位定义的特定时间点以来的历史记录。
最佳答案
这里有多个单独的问题,我认为并非所有问题都可以单独使用 Git 前端命令来解决。
首先,每次提交都有两个日期/时间戳。有一个作者日期字段和一个提交者日期字段。要查看两者,请使用 git log --format=fuller 例如:
commit 5571d085b3c9c2aa9470a10bcf2b8518d3e4ec99
Merge: bedb914551 5cf8e06474
Author: Junio C Hamano <gitster pobox.com>
AuthorDate: Wed Jul 18 12:20:35 2018 -0700
Commit: Junio C Hamano <gitster pobox.com>
CommitDate: Wed Jul 18 12:20:35 2018 -0700
虽然两者通常完全相同(如本例所示),但有时并非如此:
commit 88a8ecaeaa87a84100c4eb49fb9af7a77977cc1b
Author: Stefan Beller <sbeller google.com>
AuthorDate: Thu Jun 28 19:10:48 2018 -0700
Commit: Junio C Hamano <gitster pobox.com>
CommitDate: Fri Jun 29 09:29:44 2018 -0700
--since
和 --until
操作适用于提交者日期,但默认显示作者日期。请参阅我对 How to get git to show commits in a specified date range for author date? 的回答另请参阅Tim Beigeleisen's answer ,它展示了如何使用格式化指令以适合在 awk 或类似工具中使用的特定格式提取特定日期。
剩下的问题就是您已经发现的问题:时区信息很棘手。在这里,请参阅git: timezone and timestamp format请注意,格式化指令 %ai
和 %ci
不遵循 --date=
,而是遵循 %ad
和%cd
可以。 --date=
指令随着时间的推移而扩展,因此从 Git 2.14 开始,您可以使用 --date=local
、--date=format- local:...
等等(并且有测试来确保一切正常)。请参阅提交 6eced3ec5e5d7fbe61de2791e2627b1acf1246b3特别是。
关于Git log --since=<自纪元以来的秒数> 行为不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952684/