0

Suppose a git repo has 12 commits and 4 was created yesterday (let's say December 31st, 2199).

git log --oneline will output:

9675a65 fix: a bug in feature B
041e1b2 feat: add feature B
d0f58e3 refactor: apply DPs to feature A
e933840 feat: add feature A
a6a235d chore: update version
...

f982bfd chore: initial commit

Expected behavior

From my understanding, if I run git log --since=1.day today (January 1st, 2200) I should get an output including the last 4 commits from yesterday (in the example: from feat: add feature A to fix: a bug in feature B).

Actual behavior

But instead, I am getting only the last 3 commits (from refactor: apply DPs to feature A to fix: a bug in feature B). git log --since=1.day is not including the first commit created yesterday in its output (the feat: add feature A).

Am I missing something here?

Wesley Gonçalves
  • 1,985
  • 2
  • 19
  • 22
  • 1
    Watch out for time anomalies (time zone issues for instance, or the clock being wrong on some committer's computer) and note that "since" means *after* and "1.day.ago" means "24.hours.ago" which means "2073600 seconds ago". These are also applied to committer timestamps (there's no option to use author timestamps here). – torek Jul 19 '20 at 16:45
  • @torek, I just checked the commit times and It is about the *24.hours.ago*. But is there an option to output all the commits created yesterday only? I tried `--before=2020-07-19 --after=2020-07-18` but it still outputs like *24.hours.ago*. – Wesley Gonçalves Jul 19 '20 at 17:04
  • I just figured it out that the flag `--after=2020-07-18-00:00:00` do this trick – Wesley Gonçalves Jul 19 '20 at 17:05
  • @torek Do you want to post your answer? – Wesley Gonçalves Jul 19 '20 at 17:06

1 Answers1

2

Computer time is always more complicated than it looks.

In this case it appears it was just that you were thinking in terms of selecting commits from a particular day. In Git, however, --since (or --after, which has the same meaning) computes an exact second:

--after=2020-07-18

means "after whatever time it is now, but on that day", and:

--after=1.day.ago

means "after 24 hours since exactly 1 day ago" or "subtract 86400 seconds from this second, and use that as the after value". You can, as you commented, be more precise:

--after=2020-07-18-00:00:00

to force Git to use midnight of the specified date.

Note that --before/--until and --after/--since always work with the committer timestamp, not the author timestamp. See also Specification for syntax of git dates and this blog entry at alexpeattie.com as linked from this answer. For more background, see Falsehoods programmers believe about time.

Wesley Gonçalves
  • 1,985
  • 2
  • 19
  • 22
torek
  • 448,244
  • 59
  • 642
  • 775