The index file shouldn't just randomly change. That is the staging tree, a buffer between the repository of commits and the working tree. For efficiency, it also stores some metadata about the working tree (the checked out files which you can modify), which would allow faster status
or diff
results. To see what kind of such information is stored, try to execute git ls-files --debug
. This should print, for each file and directory, something like:
path/to/file
ctime: 1332898839:873326227
mtime: 1332898839:873326227
dev: 2052 ino: 4356685
uid: 1000 gid: 100
size: 3065 flags: 6c
So, if a file changes in any way on the disk, not as its content, but internal stuff like which inode it's using, it will trigger an update to the index
file next time the index is used.
git branch
doesn't update the index, since it only checks the .git/HEAD
file and the .git/refs/heads
and .git/packed-refs
files, it doesn't care about the index or the working tree. git diff
and git status
, on the other hand, do work with the index.
I did an experiment: I copied the current index
file, I created a new version of a file making sure that a new inode will be assigned to it (copy, remove original, rename the copy back to the original name), executed git status
, and then compared the new index file with the original copy. Two things changed: a line that contained the affected file in it, and the changes were in the bytes right before the filename, and a few bytes right at the end of the index file, probably a timestamp for the last index computation. The overall size of the file remained the same.
Back to your problem, if you're not executing any command that touches the index yourself, then maybe you have another tool that does that for you: an IDE plugin or a file browser extension that knows about git repositories, and which checks the status of git repositories. Or, there's another process that changes the way files are stored on disk, like a disk-defrag utility.