1. Ignore an extension throughout the project
In the root .gitignore, this pattern matches app.log, logs/app.log and src/app.log. * matches zero or more characters other than /; with no slash in the pattern, Git checks names at any depth below this .gitignore.
Write each pattern on its own line. These are Git ignore patterns, not shell commands or regular expressions; braces such as *.{log,tmp} are not a list of extensions in this syntax.
*.log 2. Limit the pattern to a directory
The first alternative below matches logs/app.log directly inside logs, but not logs/archive/app.log. The second matches both: /**/ allows zero or more intermediate directories. Neither matches src/app.log.
Apply one alternative at a time when comparing results. A trailing directory exclusion such as /logs/ can also hide nested files by excluding their parent, so check other rules before judging a wildcard.
/logs/*.log/logs/**/*.log 3. Check representative paths
After choosing one rule and creating the three untracked sample files, inspect their matching patterns:
git check-ignore -v -- logs/app.log logs/archive/app.log src/app.logWith /logs/**/*.log, both paths below logs should match and src/app.log should not. A verbose match beginning with ! is an exception. If your goal is to retain one file, use an explicit exception and keep its parent directories traversable.
For exact behavior and further details, consult the official references: Git documentation · git check-ignore documentation