You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cygwin环境下Git提交未适配夏令时,如何修复?

问题背景

我在Windows 11电脑上使用以下环境:

  • Git:2.46.2.windows.1
  • Cygwin:3.5.4(64位),附带GNU Bash:5.2.21(1)-release (x86_64-pc-cygwin)
  • 时区为Europe/Brussels,当前处于夏令时(DST),对应时区为CEST(+0200)
现象对比

PowerShell提交代码:时区显示正常

在PowerShell中提交代码后,git log --pretty=fuller显示的AuthorDate和CommitDate时区为预期的+0200:

PS C:\Users\StevenVolckaert\Repos\stevenvolckaert\test-repo> git commit -m "Initial commit"
[main (root-commit) 76da599] Initial commit
 1 file changed, 26 insertions(+)
 create mode 100644 .gitignore
PS C:\Users\StevenVolckaert\Repos\stevenvolckaert\test-repo> git log --pretty=fuller
commit 76da5992307b39acc1ccdcd6258a4e395a4cbd95 (HEAD -> main)
Author:     Steven Volckaert <steven.volckaert@foobar.com>
AuthorDate: Thu Oct 3 10:39:44 2024 +0200
Commit:     Steven Volckaert <steven.volckaert@foobar.com>
CommitDate: Thu Oct 3 10:39:44 2024 +0200

    Initial commit
PS C:\Users\StevenVolckaert\Repos\stevenvolckaert\test-repo>

Cygwin Bash提交代码:时区异常

在Bash中执行git log能正常显示PowerShell提交的记录,但在Bash中提交代码时,AuthorDate和CommitDate会被减1小时,时区显示为+0100:

~/Repos/stevenvolckaert/test-repo$ git commit -m "Add .gitattributes"
[main e6fe6e7] Add .gitattributes
 1 file changed, 269 insertions(+)
 create mode 100644 .gitattributes
~/Repos/stevenvolckaert/test-repo$
~/Repos/stevenvolckaert/test-repo$ git log --pretty=fuller
commit e6fe6e7b9162a34f8e09845d781bc545e9a67e26 (HEAD -> main)
Author:     Steven Volckaert <steven.volckaert@foobar.com>
AuthorDate: Thu Oct 3 09:47:05 2024 +0100
Commit:     Steven Volckaert <steven.volckaert@foobar.com>
CommitDate: Thu Oct 3 09:47:05 2024 +0100

    Add .gitattributes

commit 76da5992307b39acc1ccdcd6258a4e395a4cbd95
Author:     Steven Volckaert <steven.volckaert@foobar.com>
AuthorDate: Thu Oct 3 10:39:44 2024 +0200
Commit:     Steven Volckaert <steven.volckaert@foobar.com>
CommitDate: Thu Oct 3 10:39:44 2024 +0200

    Initial commit
~/Repos/stevenvolckaert/test-repo$
尝试过的无效方法

我尝试在git commit命令中覆盖LC_ALL或LC_TIME环境变量,但提交后的日期仍显示为+0100:

~/Repos/stevenvolckaert/test-repo$ LC_ALL=en_BE git commit --amend --no-edit --reset-author --date=now
[main d193abd] Add .gitattributes
 Date: Thu Oct 3 09:52:48 2024 +0100
 1 file changed, 269 insertions(+)
 create mode 100644 .gitattributes
~/Repos/stevenvolckaert/test-repo$ git log --pretty=fuller
commit d193abd6bb8cb93f47fc9cfb16d908538bf79e5f (HEAD -> main)
Author:     Steven Volckaert <steven.volckaert@foobar.com>
AuthorDate: Thu Oct 3 09:52:48 2024 +0100
Commit:     Steven Volckaert <steven.volckaert@foobar.com>
CommitDate: Thu Oct 3 09:52:48 2024 +0100

    Add .gitattributes

commit 76da5992307b39acc1ccdcd6258a4e395a4cbd95
Author:     Steven Volckaert <steven.volckaert@foobar.com>
AuthorDate: Thu Oct 3 10:39:44 2024 +0200
Commit:     Steven Volckaert <steven.volckaert@foobar.com>
CommitDate: Thu Oct 3 10:39:44 2024 +0200

    Initial commit
~/Repos/stevenvolckaert/test-repo$
额外验证信息
  • Cygwin Bash与PowerShell中使用的Git版本均为2.46.2.windows.1,且指向同一二进制文件
  • 将代码提交到GitHub后,日期显示为GMT+2(符合预期)

请问该如何修复Cygwin Bash中提交Git代码时的时区异常问题?


内容的提问来源于stack exchange,提问作者Steven Volckaert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 18:24:53