Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Git ignore files that has the same content but updated timestamp

Tags:

git

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?

like image 495
Koala Yeung Avatar asked Feb 15 '13 03:02

Koala Yeung


People also ask

Does Git preserve file timestamps?

NO, Git simply does not store such (meta-)information, unless you use third-party tools like metastore or git-cache-meta. The only timestamp that get stored is the time a patch/change was created (author time), and the time the commit was created (committer time).

How do you Git ignore a file that is already tracked?

Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.

Why does Git show that all my files changed when I didn't change them?

These changes mean that metadata about your file changed, however the content of your file did not. If you're working in a group, this may start to intefere with pushes or just add noise to your commits.

What should be ignored in Git?

gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.


1 Answers

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.

like image 62
manojlds Avatar answered Sep 21 '22 15:09

manojlds