显示版本控制文件,否则将被当前 .gitignore 忽略

Show version controlled files that would otherwise be ignored by current .gitignore

标题说明了一切。

举个简单的例子:在时间 t1,存储库包含扩展名为 .A.B 的文件。在稍后的时间 t2,我们决定向 .gitignore 文件添加 .B 扩展。我想列出当前受版本控制的扩展名为 .B 的文件(不是要删除它们,只是想知道它们是 if/where)。

当然,在我的例子中,它不仅仅是一个扩展,而是添加到 .gitignore 中的许多不同的模式。对于一般维护目的,了解它也很有用。

注意:我对不受版本控制的忽略文件不感兴趣,我知道您可以使用 git status -i.

列出这些文件

这应该可以为您完成工作,因为您提到文件已经在版本控制下 - 如果它们是新的,则只需将 --others 添加到命令中即可。

git ls-files -i --exclude-standard

您不必将它们添加到 .giignore,您也可以使用此:

--[no-]假设不变

When this flag is specified, the object names recorded for the paths are not updated.

Instead, this option sets/unsets the "assume unchanged" bit for the paths.

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

如果您需要打印出标有 --assume-unchanged 标志的文件列表:

git ls-files -v|grep '^h'