121

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

5
  • 1
    very interesting indeed.. it makes sense to me if when you provide just a date without a time, it defaults to the last second of the day.. but that is just something I am taking a stab at. Thanks for posting this. Very interesting!
    – ilan berci
    Commented Jan 31, 2013 at 3:43
  • 2
    Yes, seems so, that it without a time it defaults to the last second of the day. Stange, but no problem. But then Git should be consequent an do the same, when time without seconds is provided. So the result of git log --author="automatix" --since="2013-01-31 01:30" --pretty -- test should content 7 commits. But it contents 8. git log --author="automatix" --since="2013-01-31 01:30" --format=oneline -- test | wc => 8 34 498
    – automatix
    Commented Jan 31, 2013 at 4:04
  • I disagree. When I say “… happened after Monday”, I mean “happened after the last second of Monday” – “Monday” stands for a 24h period of time. While when I say “happened after 9 o’clock”, I mean “happened after 9:00:00.0000” – “9 o’clock” is one point in time, not a time span. Git’s interpretation makes the most sense.
    – Chronial
    Commented Jan 31, 2013 at 4:18
  • 2
    It's a good point. I would say, this logic works only with "after" -- not with "since". But in Git the keywords "since" anf "after" are synonyms (I find it linguistically dirty). git-scm.com/book/en/…
    – automatix
    Commented Jan 31, 2013 at 7:33
  • 1
    Git has two dates author date and commit date. Generally what is shown in author date and running git log --pretty=fuller shows both the dates. --since switch works with commit date values newer than what is mentioned. More on git dates - stackoverflow.com/a/11857467/3940047 Commented Aug 4, 2021 at 6:59

1 Answer 1

192

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)

2
  • unix timestamp also works.
    – Sarfraz
    Commented Oct 2, 2021 at 9:59
  • 1
    I'm puzzled: (1) the fact that git log defaults to one timezone or another isn't "why it works so strangely" but rather a totally separate issue, since specifying --date=local doesn't affect the strange behaviour (namely, that --since with date excludes the starting date, while --since with a date and time includes it); (2) the link to cworth.org/hgbook-git/tour doesn't mention anything about dates, times or timezones anyway -- it's just general tips. Commented Nov 2, 2023 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.