Make git ignore modification date changes if the c

2019-03-18 06:17发布

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"

标签: git git-diff
2条回答
ゆ 、 Hurt°
2楼-- · 2019-03-18 06:51

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
查看更多
姐就是有狂的资本
3楼-- · 2019-03-18 06:55

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).

查看更多
登录 后发表回答