The following command shows some metadata about the last git commit in json format:
git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{
"hash":"0fc0fc0",
"author":"Adam Matan",
"commit date":"Sun Jan 26 12:26:19 2014 +0200"}
}
Is there a way to present the date in the UTC/GMT time zone, e.g. "Sun Jan 26 10:26:19 2014"
?
Each committer's timezone is surely saved in github's server.
There are actually two different timestamps recorded by Git for each commit: the author date and the commit date. When the commit is created both the timestamps are set to the current time of the machine where the commit was made.
You can use this:
TZ=UTC0 git show --quiet --date=local --format="%cd"
If you want to control the date format, you can do this:
TZ=UTC0 git show --quiet --date='format-local:%Y%m%dT%H%M%SZ' --format="%cd"
Update 2021-10-16: changed TZ=UTC
to TZ=UTC0
thanks to @alex-shpilkin.
I don't see an utc format in the log data formats (listed this answer).
The closest I get from your format is:
git config log.date local
C:\Users\VonC\prog\git\git\>git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{"hash":"b594c97", "author":"Junio C Hamano", "commit date":"Thu Jan 23 10:00:28 2014 -0800"}
C:\Users\VonC\prog\git\git\>git config log.date local
C:\Users\VonC\prog\git\git\Documentation\technical>git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{"hash":"b594c97", "author":"Junio C Hamano", "commit date":"Thu Jan 23 19:00:28 2014"}
So from iso:
"Thu Jan 23 10:00:28 2014 -0800"
To local:
"Thu Jan 23 19:00:28 2014"
As commented, this is not UTC, unless the your machine local time is already UTC.
That was discussed on the mailing list:
Adding
user.hideTimezone
for setting UTC timezoneAuthoring and sharing a commit by default exposes the user's time zone.
"
commit --date=YYYY-MM-DDThh:mm:ss+0000
" suffices to put the author time in UTC but not the commit time in UTC.
But the user shouldn't have to pass a flag at all.Git should entirely stop accessing, recording, and sharing the user's time zone, full stop.
Failing that, git should by default stop accessing, recording, and sharing the user's time zone, but if individual users want to have their time zones on their commits, they can opt into it.
Junio C. Hamano, Git maintainer, answered:
You are free to run
$ TZ=GMT git commit
if you wanted to opt out of the feature, but this has been the default since day one and people expect Git to behave this way.
Also:
For now, using the
--date
argument on git commit allows you to also pass a timezone:git commit --date="$(TZ=PST date)"
This patch (for adding a user.hideTimezone
) is yet to be fully developed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With