Git改变文件的修改时间

发布于 2024-08-21 12:35:34 字数 1385 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把人绕傻吧 2024-08-28 12:35:35

我注意到 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 :)

心不设防 2024-08-28 12:35:34

这不会发生在 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

当您仅签出修改后的文件时,看看 BusTests.h 修改标记是否被修改会很有趣:

git checkout -- tests/BusTests.c

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:

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

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 -- tests/BusTests.c
夕嗳→ 2024-08-28 12:35:34
git ls-files -m | xargs git co --

有助于仅签出修改过的文件。但我仍然无法解释为什么 git checkout 会导致问题。

git ls-files -m | xargs git co --

helps to checkout only the modified files. But I still can't explain, why git checkout causes the problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文