Git
简体中文 ▾ Topics ▾ Latest version ▾ git-check-ignore last updated in 2.44.0

名称

git-check-ignore - 调试 gitignore / 排除文件

概述

git check-ignore [<选项>] <路径名>…​
git check-ignore [<选项>] --stdin

描述

对于通过命令行或通过 --stdin 从文件中给出的每个路径名,检查该文件是否被 .gitignore(或排除机制的其他输入文件)排除,如果被排除,则输出路径。

默认情况下,不显示跟踪文件,因为它们不受排除规则的限制;但请参阅 --no-index

选项

-q, --quiet

Don’t output anything, just set exit status. This is only valid with a single pathname.

-v, --verbose

Instead of printing the paths that are excluded, for each path that matches an exclude pattern, print the exclude pattern together with the path. (Matching an exclude pattern usually means the path is excluded, but if the pattern begins with "!" then it is a negated pattern and matching it means the path is NOT excluded.)

关于排除源内部和排除源之间的优先级规则,请参见 gitignore[5]

--stdin

从标准输入中读取路径名,每行一个,而不是从命令行读取。

-z

The output format is modified to be machine-parsable (see below). If --stdin is also given, input paths are separated with a NUL character instead of a linefeed character.

-n, --non-matching

Show given paths which don’t match any pattern. This only makes sense when --verbose is enabled, otherwise it would not be possible to distinguish between paths which match a pattern and those which don’t.

--no-index

进行检查时不要查看索引。这可以用来调试为什么某个路径会被 git add . 追踪,而不是像用户期望的那样被规则忽略,或者在开发包括否定在内的模式以匹配之前用 git add -f 添加的路径时使用。

输出

By default, any of the given pathnames which match an ignore pattern will be output, one per line. If no pattern matches a given path, nothing will be output for that path; this means that path will not be ignored.

如果指定了 --verbose,输出将是一系列格式的行:

<source> <COLON> <linenum> <COLON> <模式> <HT> <路径名>

<pathname> is the path of a file being queried, <pattern> is the matching pattern, <source> is the pattern’s source file, and <linenum> is the line number of the pattern within that source. If the pattern contained a "!" prefix or "/" suffix, it will be preserved in the output. <source> will be an absolute path when referring to the file configured by core.excludesFile, or relative to the repository root when referring to .git/info/exclude or a per-directory exclude file.

如果指定了 -z,输出中的路径名将以空字符分隔;如果还指定了 --verbose,则空字符也将取代冒号和硬制表符:

<source> <NULL> <linenum> <NULL> <模式> <NULL> <路径名> <NULL>

If -n or --non-matching are specified, non-matching pathnames will also be output, in which case all fields in each output record except for <pathname> will be empty. This can be useful when running non-interactively, so that files can be incrementally streamed to STDIN of a long-running check-ignore process, and for each of these files, STDOUT will indicate whether that file matched a pattern or not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn’t match any pattern, or that the output hadn’t been generated yet.)

Buffering happens as documented under the GIT_FLUSH option in git[1]. The caller is responsible for avoiding deadlocks caused by overfilling an input buffer or reading from an empty output buffer.

退出状态码

0

一个或多个提供的路径被忽略。

1

所提供的路径都不会被忽略。

128

遇到致命错误。

GIT

属于 git[1] 文档

scroll-to-top