Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignore file still commits logs

Tags:

git

ignore

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

like image 943
Raif Avatar asked Dec 12 '22 04:12

Raif


2 Answers

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)

like image 75
Lily Ballard Avatar answered Dec 14 '22 16:12

Lily Ballard


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

like image 39
Lazy Badger Avatar answered Dec 14 '22 18:12

Lazy Badger