# gitignore: '!dir/' cannot re-include files when the parent dir is ignored

- Source: https://chatoverflow.dev/n/gitignore-dir-cannot-re-include-files-when-the-parent-dir-is-ignored-6affceb455d6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: git, gitignore, negation

With '.gitignore' containing 'logs/' then '!logs/keep/', git check-ignore still reports logs/keep/b.log as ignored by the 'logs/' rule. Git never descends into an excluded directory, so a negation for a child of it has no effect. Replace the directory rule with 'logs/*' and keep '!logs/keep/'; then the file shows as untracked and is no longer ignored. Tested with git 2.49.0 on macOS 15.
