8

Normally I use two PCs, say: PC1 and PC2.

On both of them I'm using CygWin on Windows 10.

They had the same configuration.

On PC1 I was trying to do some adjustments on how to display the date and time when doing:

$ git log

I was trying multiple bash and git commands.

In the past and also currently on PC2 when I do:

$ date

I get the following:

Tue Sep 25 16:17:34 CDT 2018

but on PC1 (the wrong one), with the same command, I get:

Tue, Sep 25, 2018 16:17:34

where you can see that the TimeZone indicator is not showing up.

Also, now on PC1, when I do a commit and then list the history with: $ git log, dates are like:

Date:   Tue Sep 25 22:58:42 2018 +0100

where it should be:

Date:   Tue Sep 25 16:58:42 2018 -0500

because my current timezone is: CDT (America/Chicago) (-05:00)

Any idea on how to solve this?

Thanks!

[EDIT 1]

Responding to suggestion from @Johan below where he said:

--- begin of comment ---

You need to set the git log --date to local.

git config --global log.date local

--- end of comment ---

I just tried that and now the date that shows up on my last commit doesn't have the TimeZone indicator. Using the same time reference as before it would be:

Date:   Tue Sep 25 22:58:42 2018

I need to get the TimeZone indicator on the commit list.

[EDIT 2]

Responding to suggestion from @Johan below where he said:

--- begin of comment ---

You need to set the git log --date to default.

git config --global log.date default

--- end of comment ---

I just tried that and now and I get again:

Date:   Tue Sep 25 22:58:42 2018 +0100

even trying new commits.

David Smith
  • 481
  • 1
  • 5
  • 14

3 Answers3

2

You need to set the git log --date to default.

git config --global log.date default

Source: git: timezone and timestamp format

Johan
  • 3,577
  • 1
  • 14
  • 28
  • I answered on `[Edit 1]` above. – David Smith Sep 25 '18 at 22:27
  • Sorry @DavidSmith I misunderstood your question. I thought you wanted to get rid of the timezone and show it in local time. My bad. The `default` setting should solve it. I have updated my answer to it. Please try it and tell if it solves it. – Johan Sep 25 '18 at 22:33
  • thank you @Johan, unfortunatelly didn't. I answered on `[Edit 2]` above. – David Smith Sep 25 '18 at 22:36
  • Okay, there's some trial and error :) You can also define your own timezone format, in your case it would look like: `format:"%a %b %d %H:%M:%S %Y %z"`. Otherwise I would guess there's some underlying issue with the timezone. [This was the only thing](http://www.cygwin.com/cygwin-ug-net/tzset.html) I could find on timezones for Cygwin – Johan Sep 25 '18 at 22:48
  • By the way, you can test the different settings by using `git log --date=` instead of changing the settings for each try – Johan Sep 25 '18 at 22:50
  • This might also be of interest: [Emacs and Git show wrong time on Windows](https://stackoverflow.com/questions/16884170/emacs-and-git-show-wrong-time-on-windows) – Johan Sep 25 '18 at 22:56
1

I don’t think this will address the root issue on your system, but it will certainly help with git’s commit dates. Git uses an environment variable called TZ to set the timezone (for any command, not only commit), so you can set an alias for it in your shell:

alias git='TZ=CDT /usr/bin/git'
Bogdan D
  • 5,321
  • 2
  • 31
  • 32
  • I think this is the most robust solution for "set and forget", unfortunately. If you're concerned about Git being invoked without the environment variable set, you can write a pre-commit hook that will block such commits. – Resigned June 2023 Sep 22 '20 at 03:00
0

Check if the issue persists when:

  • using a regular CMD
  • setting a simplified PATH

That is:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

Note that with that setup, you benefit from 200+ Linux-like commands without even opening a bash (again, from a regular CMD session): you can type ls -alrth or grep or ... (directly from the CMD, no bash)

Since the date used in a commit is directly from the system, if time /T returns the proper hour (including DST), you won't have any issue with a git log date.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250