21

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"

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Dmitriy M
  • 297
  • 1
  • 2
  • 7
  • Tell me about your line ending configuration... – Edward Thomson Feb 08 '16 at 15:22
  • I wonder if it has anything to do with file modes as you mention you use windows in a comment below. See: http://stackoverflow.com/a/1580644/908677 – Elijah Lofgren Feb 16 '16 at 20:45
  • Here's an experiment in support that `git diff` does consider modification time: `$ git diff --exit-code; echo $? 0 $ touch -m file.txt $ git diff --exit-code; echo $? 1` – Yann Oct 31 '16 at 16:22
  • @Yann: That contradicts what I showed in my reply. Are you sure the file existed before you touched it? – choroba Jan 12 '17 at 10:16
  • Absolutely. `touch -m file.txt`, then running `git diff --exit-code --stats` returns: file.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) Exit code is 1 I'm using git version 2.11.1.windows.1 – Yann Apr 06 '17 at 12:18

2 Answers2

28

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

Anton Savin
  • 40,838
  • 8
  • 54
  • 90
3

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
choroba
  • 231,213
  • 25
  • 204
  • 289
  • 6
    nevertheless it does in this case. it literally tells me "the file modification time has changed but the file hasnt, rescaning..." and then after rescaning it all repeats again – Dmitriy M Feb 01 '16 at 20:32
  • 1
    What git client do you use? – choroba Feb 01 '16 at 20:38
  • I've tried the above with `git citool`, and I don't see the `touch`ed file as being modified either. What version of git are you using? – Daisy Leigh Brenecki Feb 01 '16 at 20:41
  • I'm thinking the problem is with the way python touches those files. As i've mentioned above python reads file into object, assigns "new" values to each attribute and element (most of the time "new" value is the same as the old one) and than rewrites it. I use git bash for win, version is slightly outdated, gonna try to update it now, perhaps that's really the case – Dmitriy M Feb 02 '16 at 07:42
  • 3
    I've updated git but the problem remains. I've updated the question with an exact quote from error message – Dmitriy M Feb 02 '16 at 08:24