git/Q/Why does git check-ignore report nothing for a tracked file?
Properties
- logseq-entity
- Logseq/Entity/Question
- see-also
- rulesync/gitignore, rulesync/Ignore
Why does
git check-ignorereport nothing for a tracked file?Answer
- AI/Response
- Because a tracked file is not being ignored, whatever
.gitignoresays about its path.git check-ignoreanswers "is git ignoring this path right now", and tracked files are exempt from ignore rules, so the pattern that matches the path is never reported.--no-indexswitches the question to "does a pattern match this path", which is the question an audit is actually asking. - Measured in a throwaway repository with
**/CLAUDE.mdin.gitignoreandsub/CLAUDE.mdforce-added and committed: Command Output Exit git check-ignore -v sub/CLAUDE.mdnone 1git check-ignore -v --no-index sub/CLAUDE.md.gitignore:1:**/CLAUDE.md0git check-ignore -v CLAUDE.md(untracked, same pattern).gitignore:1:**/CLAUDE.md0- Exit
1with no output is what makes this costly. It is the same result the command gives for a path no pattern matches, so a script or a reader treats "tracked, therefore exempt" and "no rule covers this" as one answer. The untracked row shows the pattern is real and the command can see it. When to use which
- Auditing whether a rule covers a path — use
--no-index. This is the case whenever the question is about.gitignoreitself, including whether a repository's ignore file and its tracked contents disagree. - Asking why a file is not showing up in
git status— the plain form is right, because that is a question about the file's current state. - Asking whether a directory's contents are published — neither form answers it.
git ls-files <dir>does, because it lists what is actually tracked.
- Auditing whether a rule covers a path — use
The separate trap with the same symptom
- Because a tracked file is not being ignored, whatever
- AI/Response