Search code examples
gitgitignore

Gitignore file not ignoring files from above directory


I'm trying to configure my .gitignore file so that I don't track any of my log files. However, it's not working properly and I'm not sure what's wrong.

Right now, the directory structure looks like this:

project_name
    - logs
        - logfile1
        - logfile2
    - src
        - file1.py
        - file2.py
        - .git
        - .gitignore
        - __pycache__/

The contents of my .gitignore file are:

__pycache__/
../logs/
logs/
../logs/log*

It's ignoring __pycache__ just fine, but Git is telling me that logs needs to be tracked.


Solution

  • Documentation is specific about that (emphasis mine):

    Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.

    Your .gitignore file is not in any of the parent directories of logs directory, so it has no effect.