You are completely correct here:
-
The thing you’re using here, which Git variously calls the index, the staging area, or the cache, does in fact contain cache data.
-
The cache data that it contains is the result of system calls.
-
The system call data returned by a Linux system is different from the system call data returned by a Windows system.
Hence, an OS switch completely invalidates all the cache data.
… how can I use set the index file for different system?
Your best bet here is not to do this at all. Make two different work-trees, or perhaps even two different repositories. But, if that’s more painful than this other alternative, try out these ideas:
The actual index file that Git uses merely defaults to .git/index
. You can specify a different file by setting GIT_INDEX_FILE
to some other (relative or absolute) path. So you could have .git/index-linux
and .git/index-windows
, and set GIT_INDEX_FILE
based on whichever OS you’re using.
Some Git commands use a temporary index. They do this by setting GIT_INDEX_FILE
themselves. If they un-set it afterward, they may accidentally use .git/index
at this point. So another option is to rename .git/index
out of the way when switching OSes. Keep a .git/index-windows
and .git/index-linux
as before, but rename whichever one is in use to .git/index
while it’s in use, then rename it to .git/index-name
before switching to the other system.
Again, I don’t recommend attempting either of these methods, but they are likely to work, more or less.