Show git ISO timestamps in custom timezone?

With --date=local git log , dates are displayed in my (user) time zone:

 $ 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 [...] Effective only for dates displayed in a readable format, for example when using --pretty.

But with the ISO %ci format, it does not take effect, essentially --date=local and --date=default produce the 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 detailed format in my local timezone? Ideally, I would like to see them in '%C%m%dT%H%M%S' to use the unix date syntax.

+5
git datetime
Jan 13 '15 at 17:40
source share
2 answers

It seems that it is not possible to display %ci (ISO time format) converted to the local user time zone; it is always displayed in the time zone of the committer. You can use %ct and parse the output and reformat it with a utility like date or another script, or use %cd .

0
Jan 14 '15 at 14:00
source share

This is possible with git 2.7 (Q4 2015), which introduces -local as an instruction.

This means that in addition to:

 --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) 

Now you can request the date format using your local time zone .

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 (September 03, 2015) John Keeping ( johnkeeping ) .
See commit add00ba , commit 547ed71 (September 03, 2015) by Jeff King ( peff ) .
(the merger of Junio ​​S Hamano - gitster - to commit 7b09c45 , 05 October 2015)

In particular, commit add00ba mentions:

date : make " local " orthogonal to the date:

Most of the “ --date ” modes relate to the date format: which elements we show and in what order.
But " --date=local " is a bit strange. This means "show the date in the usual format, but using the local time zone."
The time zone we use is orthogonal to the actual format, and there is no reason why we couldn’t "localize iso8601", etc.

This patch adds the boolean field " local " to " struct date_mode " and discards the DATE_LOCAL element from the date_mode_type enumeration (now it is just DATE_NORMAL plus local=1 ).
A new feature is available to users by adding " -local " to any date mode (for example, " iso-local "), and we save " local " as an alias for " default-local " for backward compatibility.

+6
Oct 07 '15 at 11:08
source share



All Articles