← 返回命令列表

Linux command

git-check-ignore 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Check if file is ignored

git check-ignore [file.txt]

Show matching rule

git check-ignore -v [file.txt]

Check multiple files

git check-ignore [file1.txt] [file2.txt]

Read paths from stdin

echo "[path]" | git check-ignore --stdin

Check all ignored files

git check-ignore *

说明

git check-ignore debugs gitignore patterns. It reports whether paths are ignored and which pattern causes the ignore, helping troubleshoot gitignore rules. The verbose mode (-v) shows the gitignore file, line number, and pattern responsible for ignoring a path. This is essential for debugging complex gitignore configurations with multiple .gitignore files at different directory levels. The --non-matching option combined with -v can also show why a file is _not_ being ignored, helping diagnose cases where files unexpectedly appear in git status output.

参数

-v, --verbose
Show source and pattern.
--stdin
Read paths from stdin.
-z
NUL-terminate output.
-n, --non-matching
Show non-matching paths.
-q, --quiet
Exit with status only.
--help
Display help information.

FAQ

What is the git-check-ignore command used for?

git check-ignore debugs gitignore patterns. It reports whether paths are ignored and which pattern causes the ignore, helping troubleshoot gitignore rules. The verbose mode (-v) shows the gitignore file, line number, and pattern responsible for ignoring a path. This is essential for debugging complex gitignore configurations with multiple .gitignore files at different directory levels. The --non-matching option combined with -v can also show why a file is _not_ being ignored, helping diagnose cases where files unexpectedly appear in git status output.

How do I run a basic git-check-ignore example?

Run `git check-ignore [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -v, --verbose do in git-check-ignore?

Show source and pattern.