11

With --date=local git log shows dates in my (user's) timezone:

$ git log  --date=local -3 --pretty=tformat:'%cd %h' --abbrev-commit 
Thu Dec 18 15:22:11 2014 dc20f74
Thu Dec 18 14:01:26 2014 06c214f
Tue Nov 4 03:48:44 2014 ac33158

The man-page says

-- date [...] Only takes effect for dates shown in human-readable format, such as when using --pretty.

But with ISO format %ci it does not take effect, as a matter of fact --date=local and --date=default product the exact same output:

$ git log  --date=local -3 --pretty=tformat:'%ci %h' --abbrev-commit 
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158

$ git log  --date=default -3 --pretty=tformat:'%ci %h' --abbrev-commit 
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158

How can I see git log in a less verbose format in my local timezone? Ideally I would like to to see them in '%C%m%dT%H%M%S', to use the unix date syntax.

Miserable Variable
  • 28,432
  • 15
  • 72
  • 133
  • Your second comment has `--date=default` specified while your first has `--date=local`. Is this intentional? "default shows timestamps in the original timezone (either committer’s or author’s)," says the git manpage. – dcsohl Jan 13 '15 at 18:25
  • It was a bad paste. `--date=local` has the same output. I will update the question. – Miserable Variable Jan 13 '15 at 18:51
  • How do you know the top case is in the user's timezone? There's no timezone information printed, and the commits shown there are different from the commits shown at the bottom. It would be nice to have a little more consistency. – dcsohl Jan 13 '15 at 19:01
  • It certainly would be nice to have some consistency :) Seems I am not working hard enough on preparing my question. Give me a few minutes. – Miserable Variable Jan 13 '15 at 19:03
  • The inconsistent output was because I ran the command in different branches. I will update it now with all of them in the same branch. I am assuming the top case is is user's timezone because the values are what they would be in my timezone (-0800) – Miserable Variable Jan 13 '15 at 19:07
  • Ok, while you've been doing that I did a little reading and a little poking around and it looks like what you want is not possible, out of the box at least. You could wrap it in a script of some sort that parses the date value (recommend `%ct` for this) and reformats it. Why do you want this specific format? Maybe there's another way. – dcsohl Jan 13 '15 at 19:25
  • Thanks @dcsohl. If you create an answer from your last comment I will accept it. There is really no compelling reason (such as usage in script or parsing the date) that I needed the functionality. Guess I can make do with `%cd` – Miserable Variable Jan 13 '15 at 21:32
  • 1
    `git log --date=iso-local` will soon be possible with git 2.7. See [my answer below](http://stackoverflow.com/a/32990648/6309) – VonC Oct 07 '15 at 11:09
  • This question is a duplicate of [Retrieving git log in YYYY-MM-DD format in local time zone](https://stackoverflow.com/q/17910312/11725753) – EvgenKo423 May 05 '21 at 08:16

2 Answers2

12

It will be possible with git 2.7 (Q4 2015), which introduces -local as an instruction.

It means that, in addition of:

--date=(relative|local|default|iso|iso-strict|rfc|short|raw)

you will also have:

--date=(relative-local|default-local|iso-local|iso-strict-local|rfc-local|short-local|raw-local)

You now can ask for any date format using the local timezone.

In your case:

git log  --date=iso-local -3 --pretty=tformat:'%cd %h' --abbrev-commit
                ^^^^^^^^^
                   |____| that part is new!

See commit 99264e9, commit db7bae2, commit dc6d782, commit f3c1ba5, commit f95cecf, commit 4b1c5e1, commit 8f50d26, commit 78a8441, commit 2df4e29 (03 Sep 2015) by John Keeping (johnkeeping).
See commit add00ba, commit 547ed71 (03 Sep 2015) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 7b09c45, 05 Oct 2015)

In particular, commit add00ba mentions:

date: make "local" orthogonal to date format:

Most of our "--date" modes are about the format of the date: which items we show and in what order.
But "--date=local" is a bit of an oddball. It means "show the date in the normal format, but using the local timezone".
The timezone we use is orthogonal to the actual format, and there is no reason we could not have "localized iso8601", etc.

This patch adds a "local" boolean field to "struct date_mode", and drops the DATE_LOCAL element from the date_mode_type enum (it's now just DATE_NORMAL plus local=1).
The new feature is accessible to users by adding "-local" to any date mode (e.g., "iso-local"), and we retain "local" as an alias for "default-local" for backwards compatibility.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    This doesn't seem to work as expected, at least on Fedora with git 2.7.4-2.fc24: `git log --date=iso-local -3 --pretty=tformat:'%cd %h' --abbrev-commit` produces `2016-03-11 15:51:49 +1000 67398e9`, ie with the timezone. – seanf Jul 22 '16 at 05:43
  • @seanf Unless you live at GMT-0000 then the local timestamp will always have a timezone. This is correct behavior. If it did not have a timezone then either it's wrong, or you live in GMT/UTC. – coolaj86 Mar 28 '21 at 15:40
1

It does not seem to be possible to display %ci (ISO time format) converted to the local user's timezone; it always displays in the committer's timezone. You could use %ct and parse the output and reformat it with a utility like date or some other script, or use %cd.

dcsohl
  • 7,186
  • 1
  • 26
  • 44