2010-02-11 69 views
4

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 

現在我的問題:沒有混帳爲什麼要改變文件fileb的時間戳?我希望時間戳保持不變。

我的命令是否會導致問題?
也許有可能改爲像git checkout . --modified那樣做?

我在mingw32/windows xp下使用git version 1.6.5.1.1367.gcd48

回答

2

這不會發生在Linux文件系統上。我測試您所描述的確切的情況和我的修改時間將被保留,因爲我已經保持不變的文件:

[email protected]:~/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 

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

[email protected]:~/Desktop/test$ git checkout . 

[email protected]:~/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中的mingw32的構建一個未知的bug,你可能想將其報告給開發商:http://code.google.com/p/msysgit/issues/list

,看是否BusTests.h修改郵票被修改時,你只簽了修改後的文件會很有趣:

git checkout -- tests/BusTests.c 
+0

感謝您的努力,'git checkout - tests/BusTests.c'按預期工作。 – tanascius 2010-02-11 14:17:57

+0

我爲我的問題添加了一個完整的命令序列......也許你可以嘗試再次重現這一點? – tanascius 2010-02-12 17:52:54

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

有助於僅簽出修改後的文件。但我仍然無法解釋,爲什麼git checkout會導致問題。

0

我已經注意到了類似的問題使用Git的復位 - 硬從msysgi開始t版本1.7.0.2。 之前,它只會修改已修改文件的時間戳。 現在,它會更改所有文件的時間戳。 我回到使用1.6.5.1的原因,因爲它沒有這個問題:)