2

I have a git repository with commits done by different authors that live in different timezones.

I want to see the history using git log since a particular point in time defined by seconds since epoch.

According to the image provided - it fails. What might be the problem? screen-shot of the command

Sevastyan Savanyuk
  • 5,797
  • 4
  • 22
  • 34
  • Does it work with `TZ=UTC git log --date=raw-local`? (taken from [here](https://stackoverflow.com/a/15103333/2679935)) – julienc Aug 21 '18 at 16:17
  • I tried that, and the `--since=` parameter does not take into account that environment variable. – Sunny Patel Aug 21 '18 at 16:31

2 Answers2

3

You have multiple separate problems here, not all of which I think you can solve using the Git front end commands alone.

First, each commit has two date/time stamps. There is an author date field and a committer date field. To see both, use git log --format=fuller for instance:

commit 5571d085b3c9c2aa9470a10bcf2b8518d3e4ec99
Merge: bedb914551 5cf8e06474
Author:     Junio C Hamano <gitster pobox.com>
AuthorDate: Wed Jul 18 12:20:35 2018 -0700
Commit:     Junio C Hamano <gitster pobox.com>
CommitDate: Wed Jul 18 12:20:35 2018 -0700

While the two are often exactly the same (as in this case), sometimes they are not:

commit 88a8ecaeaa87a84100c4eb49fb9af7a77977cc1b
Author:     Stefan Beller <sbeller google.com>
AuthorDate: Thu Jun 28 19:10:48 2018 -0700
Commit:     Junio C Hamano <gitster pobox.com>
CommitDate: Fri Jun 29 09:29:44 2018 -0700

The --since and --until operations work on the committer date but the default is to show the author date. See my answer to How to get git to show commits in a specified date range for author date? See also Tim Beigeleisen's answer, which shows how to use formatting directives to extract the particular date in a particular format suitable for use in awk or similar.

The remaining problem is the one you have identified: that time zone information is tricky. Here, see git: timezone and timestamp format and note that the formatting directives %ai and %ci do not obey --date= but %ad and %cd do. The --date= directives have expanded over time, so that as of Git 2.14, you can use --date=local, --date=format-local:..., and so on (and there are tests to make sure it all works). See commit 6eced3ec5e5d7fbe61de2791e2627b1acf1246b3 in particular.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thank you. The problem was that `--since=` was acting on the committer date and `git log` output defaults to author date. If one stumbles upon the output similar to that in my question, one can verify with `git cat-file -p ` that it is indeed the case. – Sevastyan Savanyuk Aug 21 '18 at 17:58
0

I did some testing on my own, and found that after setting the appropriate timezone, that the --since= parameter operates on UTC regardless of the Environment Variable TZ setting.

This is why you're seeing the second commit because UTC is +0000 and that second commit happened after your --since setting.

Normalizing the times to UTC (hope you like my ASCII Table):

              |    Given Time    |   in UTC
---------------------------------------------
--since=value | 1534762785 +0000 | 1534762785
commit c584d9 | 1534863946 +0600 | 1534869946
commit 4143b8 | 1534762784 +0200 | 1534764784

You can see that it's still correct, and both commits fall after your --since parameter.

Tested in git 2.14.1

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
  • Thank you for the answer. I do like your table, even though it is wrong - epoch times are always presented in UTC, hence your conversions are unnecessary. Anyway, I figured out the answer to my question already. – Sevastyan Savanyuk Aug 21 '18 at 17:47