trouble with gitignore

With this .gitignore I expect that *.log files under directory test will not be included in any git transactions

:> cat ~/test/.gitignore
*/*/*.log
*/*/*__pycache__*
*/*/*out

However I have this conversation which suggests my gitignore is not defined to do what I expect.

Where is my error? Am I misinterpreting the conversation or is my .gitignore incorrect for what I expect.

:> git add .
===
:> git status
On branch master
Your branch is up to date with 'origin/master'.
===
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
    new file:   ftp.log
===
:> git restore --staged ftp.log 
===
:> git status
Untracked files:
(use "git add <file>..." to include in what will be committed)
    ftp.log
nothing added to commit but untracked files present (use "git add" to track)
Asked By: Stephen Boston

||

https://git-scm.com/docs/gitignore

Try **/*.log

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

Answered By: rannday

Familiarise yourself with https://git-scm.com/docs/gitignore#_pattern_format

An asterisk "*" matches anything except a slash.

It looks like you want *.log instead of */*/*/...; it will wildcard match all .log files in all subdirectories.

.gitignore matches files in reference to the repo’s root directory, both hard references (/foo/bar) and soft references (foo/bar).

Answered By: Nazar Androshchuk

If you just want to exclude the directory test you can add a new .gitignore to the test directory with the following:

*.log

You can also replace what you have in your current .gitignore:

*/*/*.log

with

**/*.log

to remove tracking from all .log files in directories of the project.

Answered By: Rawley Fowler
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.