15

I'm using FTP in my recent web project. And I try use git to keep a local backup of all the changes on the FTP. It seems that the FTP server failed to support MFMT command (or some other thing I got wrong), the downloaded files do not preserve their timestamps.

When I do a git diff with the newly downloaded files, Git marks every files as changed.

Is there anyway I can tell Git to commit based on the diff result instead of the timestamp?

Koala Yeung
  • 7,475
  • 3
  • 30
  • 50

3 Answers3

11

Git only sees the content of the file to determine if it is changed. It is not concerned with the timestamp if the content is the same. Make sure there really isn't any change in the content, including line endings. Try setting proper autocrlf config based on your OS if so.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 1
    This is a bit misleading. For the sake of optimization, git diff uses a variety of "tricks" to determine if a file is dirty and may false positive a file as dirty when it has not changed. The git faq even has a question: "Why does "git diff" sometimes list a file that has no changes?" https://git.wiki.kernel.org/index.php/GitFaq – DoomGoober Jul 22 '20 at 02:49
6

Another possibility is that the file permissions got changed as a side effect of the FTP process. A file with identical contents but different permissions is considered as modified by Git.

This is especially likely if you're moving files between different operating systems. I've run into it moving files between OS X and Windows using a USB stick.

neal
  • 156
  • 3
  • 8
0

I had same problem (Windows 8.1 Enterprise, git version 1.8.4.msysgit.0). I couldn't pull, becuase there were 7 files modified, although binary (including lineendings) identical. Revert didn't help. Changing the timestamp of the first file reported as modified to the time of the revision (in TotalCommander, with 1second precision) made the pull work. Repository was created by filecopy from old disk. I made several clones of the origin repository also and there were other files "different".

Hopefully this will help others with this problem. It might be a problem of Turtoise.

BTW: Do test the lineending first as it's a more usual problem.