如何摆脱“未跟踪的缓存在此系统上被禁用”的警告。

And*_*vić 2 git

运行时git status我经常收到多个警告:

$ git status
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
warning: Untracked cache is disabled on this system.
Run Code Online (Sandbox Code Playgroud)

我已将其添加到我的 .gitconfig 中:

[core]
untrackedCache = true
Run Code Online (Sandbox Code Playgroud)

甚至尝试跑步git update-index --untracked-cache。但这没有帮助。

在 Ubuntu Xenial 上使用 git v2.7.4。

是什么导致了这些警告以及如何消除它们(而不将管道错误传递给/dev/null)?

tor*_*rek 6

(VonC 的问题是一个关键线索:未跟踪的缓存要求工作树路径与存储在索引中的路径匹配。此外,系统名称(来自 的uname字段utsname)保留在那里并且也必须匹配;这会影响跨域管理的文件网络文件系统,例如 NFS 或 SMB。)

由于未跟踪的缓存在您的系统上被禁用并会导致警告,因此您可能不希望尝试启用。换句话说,保持core.untrackedCache未设置或将其设置为false。然而,core.untrackedCache这是 Git 2.8.0 版本中的一个新设置;如果你的 Git 是 2.7.4,那么你就没有它。

运行会git update-index --untracked-cache强制启用该设置(然后生成所有这些错误消息)。您可以使用git update-index --no-untracked-cache它来强制关闭它。唯一的坏影响是,git status当禁用未跟踪的缓存时,运行速度可能会变慢(可能会明显变慢)。

请注意,从 2.8.0 开始,Git 建议git update-index --test-untracked-cache在启用未跟踪缓存之前运行(使用 或--untracked-cachecore.untrackedCache = true。另请注意,如果此core设置设置为truefalse,则在更新索引时(使用),该core.untrackedCache设置将简单地复制git update-index索引。实际上是索引的设置控制了一切。使用默认值(未设置)或将其设置为keep告诉 Git 保留未跟踪缓存设置。

您还可以设置环境变量GIT_DISABLE_UNTRACKED_CACHE(为任何值)以禁用未跟踪的缓存,无论索引中的当前设置如何。(此代码似乎也在 2.7.4 中。)这将绕过警告,并且不使用未跟踪的缓存,无论索引中的设置如何。