git ignore file still commits logs

10,931

Solution 1

The pattern */[Ll]ogs/* will only match a logs folder that's one level depe. Yours is 3 levels deep. You also said ".ignore file", I hope you meant ".gitignore". Anyway, you can fix this in one of four ways:

  1. Change the pattern to src/*/[Ll]ogs/*

  2. Put the pattern */[Ll]ogs/* into src/.gitignore instead of your root .gitignore

  3. Change the pattern to just [Ll]ogs/. This will ignore any directory called "Logs" or "logs" in your entire tree. This may not be appropriate if you only want to ignore a directory of this name within your specific domain folders.

  4. Put the pattern * into src/methodfitness.web/Logs/.gitignore. This will ignore all files in that folder. The benefit of this approach is git will still create the Logs folder when doing a checkout, which may or may not be something you want to happen. If you do this, make sure to explicitly add the .gitignore file, or it will end up ignoring itself.


On a related note, the trailing * is unnecessary. You can indicate directories with your ignore pattern and it will skip the entire directory. The only time when you want the trailing * is if you need to be able to un-ignore specific files (using the prefix ! syntax, e.g. !*/[Ll]ogs/goodfile.txt)

Solution 2

In order to ignore all log directories (and content too) at any deep inside your working copy you just have to read gitignore man mage and adopt example of ignoring foo dir from man-page.

For .gitignore in the root plain

logs/

pattern do the trick

Solution 3

You can just use [Ll]ogs/ as the ignore pattern.

Putting that pattern in the .gitignore file in the root of your directory structure should ignore all directories called either Logs or logs anywhere in the directory tree.

Solution 4

Why do you use so strange method?

To ignore all files under the src/methodfitness.web/Logs/ folder, try to add to your .gitignore file appropriate line: src/methodfitness.web/Logs/

Share:
10,931
Raif
Author by

Raif

Updated on June 12, 2022

Comments

  • Raif
    Raif almost 2 years

    I'm read all kinds of post on this and I just can't get it to work.

    in my .ignore file I have

    */[Ll]ogs/*
    

    Although I have tried about a dozen other variations, everything short of explicitly naming the file, I still am commiting these files

    new file: src/methodfitness.web/Logs/Trace.log.2012-03-15

    I also had a similar problem helping a co worker exclude his web.config file but that's his problem now, I just don't want these bloody log files.

    thanks,

    R