git diff-files output changes after git status
git diff-index
does not actually check the contents of files in the working tree. Instead, it uses the stat information of the file and compares it to the index. In fact, the diff-index
man page notes:
As with other commands of this type,
git diff-index
does not actually look at the contents of the file at all. So maybekernel/sched.c
hasn’t actually changed, and it’s just that you touched it. In either case, it’s a note that you need togit update-index
it to make the index be in sync.
As the note suggests, the index's stat entry can be updated by running git update-index --refresh
before diff-files
. The man page for update-index
elaborates:
--refresh
does not calculate a new sha1 file or bring the index up-to-date for mode/content changes. But what it does do is to "re-match" the stat information of a file with the index, so that you can refresh the index for a file that hasn’t been changed but where the stat entry is out of date.For example, you’d want to do this after doing a
git read-tree
, to link up the stat index details with the proper files.
Running update-index --refresh
before diff-files
erases the symptoms I described, solving the issue.