Trace why Git still ignores a kept file
Admin ·
When a file is missing from Git status, identify the rule that applies to its path and the folder containing it. An exception can match the file name while an earlier directory decision still controls the outcome.
Identify the blocked parent directory
Load the example and select Test paths. Three of the six paths are ignored. The row for dist/keep.txt reports rule line 2 and shows dist/ as the blocked parent. Rule line 3 looks like an exception for keep.txt. The directory decision happens before Git reaches it.
Change line 2 from dist/ to dist/* and test again. Now dist/keep.txt is included by exception on line 3. To verify the same result in your repository, run git check-ignore -v --no-index -- dist/keep.txt and look for the rule beginning with !.
Git documentation, gitignore pattern formatGit documentation, git check-ignore
Compare a root slash and a globstar
The rule /logs/*.log matches logs/build.log on line 4. The path packages/logs/build.log stays eligible because that rule starts at the repository root. Line 5 uses docs/**/draft.txt, so both docs/draft.txt and docs/v2/draft.txt match.
Add a trailing slash when entering a folder path. Keep the path relative to the repository and use forward slashes between components.
Check whether the case setting explains a different result
Reload the example and test with the default setting. NOTES.TMP has no rule match. Turn on Match ASCII letters without case and test again. The same row now reports *.tmp on line 6, while important.tmp still reports its exception on line 7.
Compare the case setting, file names and rule sources with the repo. The downloaded JSON contains the path line, matching rule line, decision and blocked parent so you can diff two runs.
Git documentation, core.ignoreCase configurationGit documentation, git check-ignore
Common questions
How do I test a path already committed to Git?
In the repository, add --no-index to git check-ignore -v to inspect the pattern decision for that path. The browser tool only has your supplied rules and candidate paths.
Why can a different .gitignore file change the answer?
Git also reads nested .gitignore files and other exclude sources. Check the source file reported by git check-ignore -v when a repository differs from the root-rule simulation.