tags:

views:

250

answers:

3

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 (EDIT: added complete command sequence)

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

exxxxxxx@wxxxxxxx /d/test (master)
$ touch filea fileb

exxxxxxx@wxxxxxxx /d/test (master)
$ git add .

exxxxxxx@wxxxxxxx /d/test (master)
$ 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

exxxxxxx@wxxxxxxx /d/test (master)
$ ls -l > filea

exxxxxxx@wxxxxxxx /d/test (master)
$ touch fileb -t 200912301000

exxxxxxx@wxxxxxxx /d/test (master)
$ 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

exxxxxxx@wxxxxxxx /d/test (master)
$ 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
#

exxxxxxx@wxxxxxxx /d/test (master)
$ git checkout .

exxxxxxx@wxxxxxxx /d/test (master)
$ 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: 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 mingw32/windows xp.

A: 
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.

tanascius
+1  A: 

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 mingw32 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
seanhodges
Thanks for your effort, `git checkout -- tests/BusTests.c` works as expected.
tanascius
I added a complete command sequence to my question ... maybe you can try to reproduce this once again?
tanascius
A: 

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 :)

Kipras