I have a disk partition (format: NTFS) shared by windows and linux. It contains a git repository(about 6.7G).
If I only use windows or only use linux to manipulate the git repository everything is ok.
But everytime I switch the system. The
git status command will refresh the index and takes about 1minute. After I running the
git status, if I run the
git status in the same system again. It only take less than 1 second. Here is the result
# Just after switch from windows [#5#wangx@manjaro:duishang_design] git status # this command takes more than 60s Refresh index: 100% (2751/2751), done. On branch master nothing to commit, working tree clean [#10#wangx@manjaro:duishang_design] git status # this time the command takes less than 1s On branch master nothing to commit, working tree clean [#11#wangx@manjaro:duishang_design] git status # this time the command takes less than 1s On branch master nothing to commit, working tree clean
I guess there is some problem about the git cache. For example: windows and linux all use the
.git/index file as cache file, but the git in linux system can’t recognize the
.git/index changed by windows. So it can only refresh the index and replace the
.git/index file, which makes the next
git status super fast and
git status in windows very slow (because the windows system will refresh the index file again).
Is my guess correct? If so, how can I use set the index file for different system? How can I solve the problem?
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-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-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.
Answered By – torek