0

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.

9
  • 3
    Maybe you could create another .gitignore in the above directory? Commented Aug 6, 2020 at 2:25
  • 1
    Why should that ignore be able to control files in other directories that is not a descendant? Commented Aug 6, 2020 at 2:28
  • 2
    If you want to handle files with one .gitignore, I think you need to put the .gitignore file in the top directory of your git repo. Commented Aug 6, 2020 at 2:30
  • 1
    According to stackoverflow.com/questions/19488902/…, I think it's not possible. Maybe the source code of the git would explain why. Commented Aug 6, 2020 at 2:34
  • 2
    I'm just trying to figure out why you would expect it to. Your directory is like a box and the ignore file describes what is not in the box. You shouldn't expect it to describe what's not in other boxes. Commented Aug 6, 2020 at 2:34

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.