我有一个只有几个提交的简单测试存储库,我想查看日期和时间过滤的日志:
$ git log --author="automatix" --since="2013-01-30" --pretty -- test commit ea0719bef142659fa561c9d040b2120012ed0184 Date: Thu Jan 31 02:03:12 2013 +0100 commit ab4a8387bc4d9bdb4f67212df77eb1fc3d8b6304 Date: Thu Jan 31 01:59:11 2013 +0100 commit a0b027beba2cd03571bb9475b9db9542f8efe990 Date: Thu Jan 31 01:50:38 2013 +0100 commit add77c8fe2ba9254c11b98e14facede3420dc51c Date: Thu Jan 31 01:48:34 2013 +0100 commit e6e323c05d37c74fcabeb9186b95c0d49b862e6f Date: Thu Jan 31 01:46:27 2013 +0100 commit 8c286391e54d3fc1e210950b1320fd6f013a8f84 Date: Thu Jan 31 01:41:27 2013 +0100 commit 9c880595e57f717383796fa2940f41f0f42f7e2a Date: Thu Jan 31 01:38:17 2013 +0100 commit a95527f36a533e1ecba1aadceea31a9dcbe1a8db Date: Thu Jan 31 01:30:00 2013 +0100
第一个选择的提交是 a95527f36a533e1ecba1aadceea31a9dcbe1a8db
来自 2013-01-30 01:30:00
。选择了 8 个提交:
$ git log --author="automatix" --since="2013-01-30" --format=oneline -- test | wc 8 34 498
好的。现在我从 2013-01-31
开始选择:
$ git log --author="automatix" --since="2013-01-31" --format=oneline -- test | wc 0 0 0
什么?好的,这应该意味着 since
规则排除开始日期的提交。对吧?
但让我们继续:
$ git log --author="automatix" --since="2013-01-31 01:30:00" --pretty -- test commit ea0719bef142659fa561c9d040b2120012ed0184 Date: Thu Jan 31 02:03:12 2013 +0100 commit ab4a8387bc4d9bdb4f67212df77eb1fc3d8b6304 Date: Thu Jan 31 01:59:11 2013 +0100 commit a0b027beba2cd03571bb9475b9db9542f8efe990 Date: Thu Jan 31 01:50:38 2013 +0100 commit add77c8fe2ba9254c11b98e14facede3420dc51c Date: Thu Jan 31 01:48:34 2013 +0100 commit e6e323c05d37c74fcabeb9186b95c0d49b862e6f Date: Thu Jan 31 01:46:27 2013 +0100 commit 8c286391e54d3fc1e210950b1320fd6f013a8f84 Date: Thu Jan 31 01:41:27 2013 +0100 commit 9c880595e57f717383796fa2940f41f0f42f7e2a Date: Thu Jan 31 01:38:17 2013 +0100 commit a95527f36a533e1ecba1aadceea31a9dcbe1a8db Date: Thu Jan 31 01:30:00 2013 +0100
$ git log --author="automatix" --since="2013-01-31 01:30:00" --format=oneline -- test | wc 8 34 498
现在,当我也写开始时间时,开始时间的提交包括。
我不明白这个逻辑。任何人都可以解释为什么它如此奇怪吗?
谢谢
最佳答案
如果它能帮助像我一样登陆这里的其他人,经过一些研究我发现使用 ISO8601 format也有效:
git log --since="2014-02-12T16:36:00-07:00"
这将使您精确到秒。注意:您还可以使用:
git log --after="2014-02-12T16:36:00-07:00"
git log --before="2014-02-12T16:36:00-07:00"
git log --since="1 month ago"
git log --since="2 weeks 3 days 2 hours 30 minutes 59 seconds ago"
等等
当然,这并不能“解释为什么它工作起来如此奇怪”。但是,它确实解决了我的问题。
编辑:
经过更多的研究,我发现了“为什么它如此奇怪地工作”:
事实证明,当您不指定日期格式时,git log defaults to either the author's timezone or commit dates ,这意味着一致的行为,它是有用的明确声明你的日期格式是这样的:
git log --date=local
最后,当您未指定时间时,它默认为您运行命令时的本地时间。
长话短说,具体应该可以解决问题:
git log --date=local --after="2014-02-12T16:36:00-07:00"
此外,您还可以使用以下命令永久设置默认日期格式:
git config log.date local
您可以使用以下任一值:(relative|local|default|iso|rfc|short|raw)
关于git - git log --since 是如何计数的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14618022/