Git:当文件时间戳和大小相同时没有区别。

4

[操作]

1. Install git on windows 7  
2. Init a respo  
3. Add a new text file name "a.txt" and commit  
4. Copy a.txt to another folder:  
   4.1 Change one word in txt file, keep the same file size  
   4.2 Change file time stamp to original  
5. Copy updated a.txt back to the git respo just created  
6. Check use command "git status" or "git diff"  

结果:Git不会发现任何差异。

我的期望是git能够找到文件的差异。 我想知道原因和如何解决?

附注: 1.如果步骤4.1、4.2在respo文件夹中操作,git可以找到文件更改。 2.如果时间戳设置为未来的日期,git也可以正常运行。

[示例命令]

Set PATH=%PATH%;D:\Git\bin  

git init Test  
cd Test  

echo 123456 > a.txt  
D:\XXX\FILETIME.exe a.txt 09/29/2016 12:12:12  

git add .  
git commit -m "init a.txt"  

echo 654321 > a.txt  
D:\XXX\FILETIME.exe a.txt 09/29/2016 12:12:12  

git status  
git diff  

[日志]

C:\>git init Test  
Initialized empty Git repository in C:/Test/.git/  

C:\>cd Test  
C:\Test>echo 123456 > a.txt  

C:\Test>D:\xxx\FILETIME.exe a.txt 09/29/2016 12:12:12  
a.txt  
Creation time ...    09/29/2016 12:12:12  
Last access time ... 09/29/2016 12:12:12  
Last write time ...  09/29/2016 12:12:12  

C:\Test>git add .  

C:\Test>git commit -m "init a.txt"  
[master (root-commit) 95f91e5] init a.txt  
1 file changed, 1 insertion(+)  
create mode 100644 a.txt  

C:\Test>echo 654321 > a.txt     

C:\Test>D:\xxx\FILETIME.exe a.txt 09/29/2016 12:12:12  
a.txt  
Creation time ...    09/29/2016 12:12:12  
Last access time ... 09/29/2016 12:12:12  
Last write time ...  09/29/2016 12:12:12  

C:\Test>git status  
On branch master  
nothing to commit, working tree clean  

C:\Test>git diff 

1
请准确展示您正在执行的命令。 - Ismail Badawi
1
请参见此处:https://dev59.com/UnI-5IYBdhLWcg3wlpeW - Chris Maes
2
似乎git正在尝试使用修改时间等来确定哪个文件已更改。我知道这是一种理论情况,但是如果不是真的要实现相同大小和时间戳的两个文件,你怎么可能编辑文件并保持它们相同呢? - Chris Maes
1
这基本上是 https://dev59.com/UnI-5IYBdhLWcg3wlpeW 的重复,正如 @ChrisMaes 所指出的那样,不过你的版本有“演示重现步骤”的优点,所以我不会将其简单地关闭为重复。 :-) - torek
@ChrisMaes 一些模块由第三方提供,他们会给我类似但时间戳相同的文件内容。(时间戳将根据某些规则手动设置)当我获取这些文件并想要合并到我的资源库时,问题就会出现。 - 2000
显示剩余3条评论
1个回答

0

Git 尝试使用 stat() 函数来获取文件的状态,而不是每次运行使用工作树(例如 git statusgit diff)时访问每个文件的全部内容。

否则这将非常昂贵,并且无法解决任何正常情况下可能发生的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接