4

[Operation]

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"  

RESULT: No difference will be found by git

My expectation is git could find the file's difference. I want to know why and how?

PS: 1.If step 4.1, 4.2 operate in folder of respo, git could find the file changes. 2.If time stamp set the future's date, git also could run well

[Sample Command]

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  

[LOG]

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 
2000
  • 45
  • 5
  • I doubt there is anything wrong with Git. Most likely, the `a.txt` which you copied back is there as an untracked file, and therefore is not showing up in the change set. Look for untracked files, and you should see it there. – Tim Biegeleisen Sep 30 '16 at 04:28
  • Actually a.txt is already under tracking after my step 4 – 2000 Sep 30 '16 at 04:46
  • 1
    Please show exactly what commands you're running. – Ismail Badawi Sep 30 '16 at 04:47
  • 1
    see here: http://stackoverflow.com/questions/1778862/how-does-git-detect-that-a-file-has-been-modified – Chris Maes Sep 30 '16 at 06:12
  • 2
    It seems like git is trying to use modification times etc. to determine what file has changed. I understand this is a theoretical case, but how in the world would you edit your file and keep both the size and timestemp identical **unless** you are really trying to achieve that? – Chris Maes Sep 30 '16 at 06:14
  • 1
    This is basically a duplicate of http://stackoverflow.com/q/1778862/1256452 as @ChrisMaes noted, though your version has the advantage of "steps to reproduce a demonstration", so I won't just close it as a duplicate. :-) – torek Sep 30 '16 at 06:42
  • @ChrisMaes Some module supply by 3rd party, who will give me such kind of content different but time stamp same file. (Time stamp will be set manually according to some rule), issue will happen when I get these files and want to merge into my respo. – 2000 Oct 03 '16 at 00:25
  • @IsmailBadawi I updated the question – 2000 Oct 03 '16 at 00:26

1 Answers1

0

Git tries to stat() the files instead of accessing to the whole content of every file everytime you run a command using the worktree (git status or git diff for instance).

Doing otherwise would be extremly costly, and won't solve any case that would happen in any normal case.

blue112
  • 52,634
  • 3
  • 45
  • 54