首页/开发/Git 与协作速查/untracked cache 减少目录扫描
进阶与大仓实践69 条

untracked cache 减少目录扫描

把「哪些目录确认没有未跟踪文件」记入索引,让 git status 少扫目录;在文件数多的仓库上对状态命令有直接收益。

Git 与协作速查开发更新于 2026-10-12
启用git config core.untrackedCache true
适用目录层级深、文件数多的仓库
关闭core.untrackedCache false 并重新 status 生效

常用示例

常用示例
git update-index --untracked-cache
git config core.untrackedCache true
time git status
无兼容性问题时可长期开启;status 出现异常缓存行为时临时关闭再确认。

易错点

  • 文件系统不支持扩展属性导致缓存失效时提速有限,先测量再决定是否保留
  • 网络盘、容器挂载目录上缓存可能频繁重建,收益不稳定

数据来源与参考

  • Git 官方文档:git-config(core.untrackedCache)
  • Git 官方文档:git-update-index(--untracked-cache)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌