Git 更改文件的修改时间

标签 git msysgit

GitFaq我能读懂,那个

Git sets the current time as the timestamp on every file it modifies, but only those.

但是,我尝试了这个命令序列:

$ git init test && cd test
Initialized empty Git repository in d:/test/.git/

$ touch filea fileb

$ git add .

$ git commit -m "first commit"
[master (root-commit) fcaf171] first commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 filea
 create mode 100644 fileb

$ ls -l > filea

$ touch fileb -t 200912301000

$ ls -l
total 1
-rw-r--r--    1 exxxxxxx Administ      132 Feb 12 18:36 filea
-rw-r--r--    1 exxxxxxx Administ        0 Dec 30 10:00 fileb

$ git status -a
warning: LF will be replaced by CRLF in filea
# On branch master
warning: LF will be replaced by CRLF in filea
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#






#       modified:   filea
#

$ git checkout .

$ ls -l
total 0
-rw-r--r--    1 exxxxxxx Administ        0 Feb 12 18:36 filea
-rw-r--r--    1 exxxxxxx Administ        0 Feb 12 18:36 fileb

为什么 Git 会更改文件 fileb 的时间戳?我希望时间戳保持不变。

我的命令是否导致了问题? 也许可以做一些类似 git checkout 的事情。 --改为修改

我在 MinGW 和 Windows XP 下使用 git version 1.6.5.1.1367.gcd48

最佳答案

这不会发生在 Linux 文件系统上。我测试了您描述的确切场景,并且保留了我未触及的文件的修改时间:

sean@SEAN-PC:~/Desktop/test$ ls -la tests/BusTests.*
-r--r--r-- 1 sean sean 8 2010-02-11 11:53 tests/BusTests.c
-r--r--r-- 1 sean sean 1 2010-02-11 11:51 tests/BusTests.h

sean@SEAN-PC:~/Desktop/test$ git status -a
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   tests/BusTests.c
#

sean@SEAN-PC:~/Desktop/test$ git checkout .

sean@SEAN-PC:~/Desktop/test$ ls -la tests/BusTests.*
-r--r--r-- 1 sean sean 1 2010-02-11 11:55 tests/BusTests.c
-r--r--r-- 1 sean sean 1 2010-02-11 11:51 tests/BusTests.h

我怀疑这是 Git 的 MinGW 构建中的一个未知错误。您可能想将其报告给开发人员:http://code.google.com/p/msysgit/issues/list

当您只 checkout 修改后的文件时,看看 BusTests.h 修改戳是否被修改会很有趣:

git checkout -- tests/BusTests.c

关于Git 更改文件的修改时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2244020/

相关文章:

git - 审阅更改提交后更新 pull 请求未显示在 pull 请求中

gitlist 无法获取存储库列表之外的任何内容

git safe rebase 或 "try rebase, fallback to merge"

git - 如何将多个提交压缩到另一个分支?

windows - 在 msysgit 中取消 stash .git 文件夹有任何问题吗?

Git pull - 致命 : read error: Invalid argument

git - 如何找出分支中哪些文件已被修改?

git rebase 分支与祖 parent

windows - Windows 上的 msysgit——如果有的话,我应该注意什么?

git - 将 git 与重写 SSL 证书的代理一起使用