git log怎么样 - 计数?

aut*_*tix 69 git git-log

我有一个简单的测试存储库,只有几个提交,并希望看到日期和时间过滤日志:

$ 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规则排除了startdate的提交.对?

但是让我们继续:

$ 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

现在,当我正在编写启动时,还包括启动时的提交.

我不明白逻辑.任何人都能解释一下,为什么这么奇怪?

谢谢

gMa*_*ale 112

如果它像我一样帮助其他人登陆这里,经过一些研究后我发现使用ISO8601格式也有效:

git log --since="2014-02-12T16:36:00-07:00"
Run Code Online (Sandbox Code Playgroud)

这将使您精确到第二个.注意:您还可以使用:

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"
Run Code Online (Sandbox Code Playgroud)

等等

当然,这并没有"解释为什么它如此奇怪." 但是,它确实为我解决了这个问题.


编辑:

经过一番研究后,我发现"为什么它的工作原理如此奇怪":
事实证明,当你没有指定日期格式时,git log默认为作者的时区或提交日期,这意味着一致的行为,它是有用的用以下内容明确声明您的日期格式:

git log --date=local
Run Code Online (Sandbox Code Playgroud)

最后,如果未指定时间,则默认为运行命令时的本地时间.

长话短说,具体应该解决问题:

git log --date=local --after="2014-02-12T16:36:00-07:00"
Run Code Online (Sandbox Code Playgroud)

此外,您可以使用以下命令永久设置默认日期格式:

git config log.date local
Run Code Online (Sandbox Code Playgroud)

您可以使用以下任何一个值: (relative|local|default|iso|rfc|short|raw)