`git log --since`如何计数? [英] How does `git log --since` count?

查看:234
本文介绍了`git log --since`如何计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 
$ git log - -author =automatix--since =2013-01-30--pretty - test
commit ea0719bef142659fa561c9d040b2120012ed0184
Date:Thu Jan 31 02:03:12 2013 +0100

commit ab4a8387bc4d9bdb4f67212df77eb1fc3d8b6304
日期:2013年1月31日01:59:11 2013 +0100

提交a0b027beba2cd03571bb9475b9db9542f8efe990
日期:星期四1月31日01:50:38 2013 +0100

提交add77c8fe2ba9254c11b98e14facede3420dc51c
日期:星期四1月31日01:48:34 2013 +0100

提交e6e323c05d37c74fcabeb9186b95c0d49b862e6f
日期:星期四1月31日01:46: 27 2013 +0100

承诺8c286391e54d3fc1e210950b1320fd6f013a8f84
日期:星期四1月31日01:41:27 2013 +0100

承诺9c880595e57f717383796fa2940f41f0f42f7e2a
日期:1月31日星期四01:38:17 2013 +0100

提交a95527f36a533e1ecba1aadceea31a9dcbe1a8db
日期:星期四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

什么?好吧,那应该是说,自 rule 之后的排除了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
日期:Thu Jan 31 01:59:11 2013 +0100

commit a0b027beba2cd03571bb9475b9db9542f8efe990
日期:Thu Jan 31 01:50:38 2013 +0100

commit add77c8fe2ba9254c11b98e14facede3420dc51c
日期:Thu Jan 31 01:48:34 2013 +0100

commit e6e323c05d37c74fcabeb9186b95c0d49b862e6f
日期:星期四1月31日01:46:27 2013 +0100

犯8c286391e54d3fc1e210950b1320fd6f013a8f84
日期:星期四1月31日1点41分27秒2013 +0100

犯9c880595e57f717383796fa2940f41f0f42f7e2a
日期:星期四01年1月31日:38:17 2013 +0100

提交a95527f36a533e1ecba1aadceea31a9dcbe1a8db
日期:2013年1月31日01:30:00 +0100



 $ git log --author =automatix--since =2013-01-31 01:30:00--format = oneline  -  test | wc 
8 34 498

现在,当我编写启动时间时,启动时间的提交是包含



我不理解逻辑。任何人都可以解释,为什么它的工作原理如此奇怪?



谢谢

为了帮助其他人像我一样登陆这里,经过一番研究后,我发现使用 ISO8601格式也适用:

  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个月前
git log - since =2周3天2小时30分59秒前

等。



当然,这并不能解释它为什么如此奇怪。然而,它确实为我解决了这个问题。






编辑:

经过多一点研究后,我发现为什么它的工作原理很奇怪:

事实证明,当你不指定日期格式时, git日志默认为作者的时区或提交日期,这意味着一致的行为,这是有用的显式声明你的日期格式类似于:

  git log --date = local 

最后,当您不指定时间时,它会默认为当您运行命令时的本地时间。



长篇故事总之,具体应该解决问题:

  git log --date = local --after =2014-02-12T16 :36:00-07:00

另外,您可以使用以下命令:

  git config log.date local 
code>

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


I have a simple test repository with just several commits and want to see the date&time filtered 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

The first selected commit is a95527f36a533e1ecba1aadceea31a9dcbe1a8db from 2013-01-30 01:30:00. 8 commits are selected:

$ git log --author="automatix" --since="2013-01-30" --format=oneline -- test | wc
      8      34     498

OK. Now I select since 2013-01-31:

$ git log --author="automatix" --since="2013-01-31" --format=oneline -- test | wc
      0       0       0

What? Ok, that should mean, that the since rule excludes the commits of the startdate. Right?

But let's go on:

$ 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

Now, when I'm writing the starttime as well, the commits of the starttime are included .

I don't understand the logic. Can anybody explain, why it works so strange?

Thanks

解决方案

In case it helps someone else who lands here like I did, after a bit of researching I found out that using ISO8601 format also works:

git log --since="2014-02-12T16:36:00-07:00"

This will give you precision down to the second. Note: you can also use:

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"

etc.

Of course, this doesn't "explain why it works so strange." However, it certainly solved the problem for me.


EDIT:

After a bit more research, I found out "why it works so strangely":
It turns out that when you don't specify a date format, git log defaults to either the author's timezone or commit dates, meaning for consistent behavior, it's useful to explicitly declare your date format with something like:

git log --date=local

Lastly, when you don't specify a time, it defaults to your local time when you ran the command.

Long story short, being specific should solve the problem:

git log --date=local --after="2014-02-12T16:36:00-07:00"

Also, you can set the default date format permanently with the following command:

git config log.date local

you can use any one of these values: (relative|local|default|iso|rfc|short|raw)

这篇关于`git log --since`如何计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆