我目前正在维护一个针对 bash 的 git 提示符 ( https://github.com/magicmonty/bash-git-prompt ) 的项目,我刚从使用 Docker 的人那里收到错误报告 ( https://github.com/magicmonty/bash-git-prompt/issues/97 ),他告诉我,每次他使用提示符时,缓存失效,因为 .git
目录不断被触及。
我已经对此进行了调查,发现是命令 git status
触及了 .git
目录。
似乎只有目录条目本身没有内容被触及。
任何人都可以解释为什么需要这样做,或者这可能是 Git 中的错误。
有没有办法在不触及 .git 目录的情况下显示所有状态信息?
感谢帮助
更新:
由于使用 git status
命令的全部原因是为了确定未跟踪文件的数量,我将其替换为 git ls-files --others --exclude-standard | wc -l
,不需要锁。
最佳答案
strace git status
显示此操作使用锁定文件 .git/index.lock
,这就是为什么 .git
的 mtime已更新。
git
很酷,它使用环境变量 GIT_INDEX_FILE
来决定使用哪个锁定文件。如果未设置,git
使用 .git/index
(这是默认设置),但如果设置,git
使用它的值。来自 man git
:
GIT_INDEX_FILE
This environment allows the specification of an alternate index file. If not specified, the default of
$GIT_DIR/index
is used.
所以:
GIT_INDEX_FILE=banana git status
不会更新您的 .git
的 mtime。
因此,您现在必须决定是否要沿着这条路走(当然有很多注意事项)。
祝你好运!
关于git - 谁能解释一下,为什么 "git status"会触及 .git 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26937867/