Git改变文件的修改时间
在 GitFaq 我可以读到,
Git 将当前时间设置为其修改的每个文件的时间戳,但仅限于这些文件。
但是,我尝试了这个命令序列:
$ 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
Why did Git Change the timestamp of file fileb
?我希望时间戳保持不变。
我的命令是否引起了问题? 也许可以做类似 git checkout 的事情。 --修改 代替?
我在 MinGW 和 Windows XP 下使用 git version 1.6.5.1.1367.gcd48
。
In the GitFaq I can read, that
Git sets the current time as the timestamp on every file it modifies, but only those.
However, I tried this command sequence:
$ 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
Why did Git change the timestamp of file fileb
? I'd expect the timestamp to be unchanged.
Are my commands causing a problem?
Maybe it is possible to do something like a git checkout . --modified
instead?
I am using git version 1.6.5.1.1367.gcd48
under MinGW and Windows XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我注意到 git reset --hard 从 msysgit 版本 1.7.0.2 开始也存在类似问题。
以前,它只会更改已修改文件的时间戳。
现在,它更改所有文件的时间戳。
由于这个原因我又重新使用 1.6.5.1,因为它没有这个问题:)
I have noticed a similar problem with git reset --hard as of msysgit version 1.7.0.2.
Before, it would only change timestamps of modified files.
Now, it changes timestamps of all files.
I went back to using 1.6.5.1 for that reason, because it doesn't have this problem :)
这不会发生在 Linux 文件系统上。我测试了你所描述的确切场景,并且我的修改时间被保留为我未触及的文件:
我怀疑这是 Git 的 MinGW 版本中的一个未知错误。您可能需要向开发人员报告该问题:http://code.google.com/ p/msysgit/issues/list
当您仅签出修改后的文件时,看看 BusTests.h 修改标记是否被修改会很有趣:
This doesn't occur on a Linux filesystem. I tested the exact scenario you described and my modification times are preserved for the files I have left untouched:
I suspect that this is an unknown bug in the MinGW build of Git. You might want to report it to the developers: http://code.google.com/p/msysgit/issues/list
It would be interesting to see if the BusTests.h modification stamp is modified when you only checkout the modified file:
有助于仅签出修改过的文件。但我仍然无法解释为什么 git checkout 会导致问题。
helps to checkout only the modified files. But I still can't explain, why
git checkout
causes the problems.