Git changes file modification time

In GitFaq, I can read that

Git sets the current time as a timestamp for each file that it changes, but only those.

However, I tried this command sequence ( EDIT: added full 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 

Now my question is: why did git change the timestamp of the fileb file? I expect the timestamp to not change.

Are my teams causing the problem?
Maybe instead you can do something like git checkout . --modified git checkout . --modified ?

I am using git version 1.6.5.1.1367.gcd48 under mingw32 / windows xp.

+4
source share
3 answers

This does not happen on the Linux file system. I tested the exact script that you described, and my modification time is saved for files that I left intact:

 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 mingw32 Git build error, you can report it to the developers: http://code.google.com/p/msysgit/issues/list

It would be interesting to know if the BusTests.h modification stamp changes when you check only the modified file:

 git checkout -- tests/BusTests.c 
+2
source
 git ls-files -m | xargs git co -- 

Helps check only modified files. But I still cannot explain why git checkout is causing problems.

0
source

I noticed a similar problem with git reset --hard as of msysgit 1.7.0.2. Previously, he only changed the timestamps of modified files. Now it changes the timestamps of all files. For this reason, I returned to using 1.6.5.1, because it does not have this problem :)

0
source

Source: https://habr.com/ru/post/1300983/


All Articles