问题
I have python scripts which generate and modify different xml-files. They work so that they open a file, create an ElementTree object based on it, try to modify object's content if necessary and than save those objects into origin files.
The thing is that sometimes they don't change the content of the file even a bit. But file's modification date changes.
Git, on the other hand, treats those file as "changed" because it notices that modification date has changed. Although it won't make diffs (obviously).
citool acts crazy (alerts that date has changed but the file itself hasn't, tries to rescan them and once again shows them as "modified")
I do not have access to modify those python scripts so rewriting them is not an option (they are stored and frequently modified in a separate repo). Is there any way to tell git to ignore modification date changes for a specific folder? It's just very annoying seeing dozens of "changed" files when in fact only one of them was really modified.
I know I can stage all the files and then unstage them but it takes a couple of extra actions I would like to omit. And sometimes it just interferes with normal git workflow.
Update: git citool error reads (quote): "No differences detected. <file> has no changes. The modification date of this file was updated by another application, but the content within the file was not changed. A rescan will be automatically started to find other files which may have the same state."
Then after rescan all fake-modified files appear again.
git status also shows those files as "modified"
回答1:
You can do git add
for all affected files, after that it stops displaying them as modified in git status
(and doesn't actually stage them for commit if there are no changes). At least that worked for me (I'm using git 2.8.1).
回答2:
Git doesn't report changes in modification time.
$ git init
Initialized empty Git repository in /home/choroba/...
$ echo > a
$ git add a
$ git commit -m init
[master (root-commit) d686390] init
1 file changed, 1 insertion(+)
create mode 100644 a
$ touch -m a
$ git status
On branch master
nothing to commit, working directory clean
来源:https://stackoverflow.com/questions/35139541/make-git-ignore-modification-date-changes-if-the-content-of-the-file-stays-the-s