4

This is the content of my "root" .gitignore

# exclude everything ... * # ...except !/.gitignore !*/ !/modules/wp-azth/** 

the problem is that, under modules folder, i've a lot of third-party modules with a .gitignore file inside.

Using rules above, all third-party modules folders are ignored but their .gitignore files are not ( and i don't need it of course )

is there a way to ignore .gitignore files inside ignored subfolders? maybe .git/config can be used for this?

( i think it's a bad behaviour of git that considers them even if they are ignored )

UPDATE: It seems a lack of git, it allows ignored folder to "arbitrary" un-ignore itself having !.gitignore rule inside a gitignore file placed ( by anyone ) inside an ignored subdirectory. Ignored folders normally could contains files that are dynamic , temporary or 3rd party ( cache, temp, plugins etc ) ... so git allows to create unwanted behaviours just using a simple !.gitignore as rule inside subdirectory.

git gui screenshot

8
  • what about /**/.gitignore ? (I don't know if it's work, but this is the way i would have tryed) Commented Jan 1, 2016 at 2:58
  • Already tried ( put at the end of gitignore rules ) but it doesn't work Commented Jan 1, 2016 at 3:04
  • If you run git check-ignore -v -n on one of the files what does it say? There's probably an override somewhere in your gitignore path. Commented Jan 1, 2016 at 4:52
  • What version of git are you using? Commented Jan 1, 2016 at 7:09
  • @VonC my git version is 1.9.1 Commented Jan 2, 2016 at 11:38

2 Answers 2

2

*.gitignore will work, however git will still track .gitignore files it was already tracking


The only different between the two commands being ran is that I add *.gitignore (via the command you see in the middle) to my root level .gitignore file.

Showing *.gitignore works


An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.

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

Meaning it might be possible that a middle level .gitignore file(s) has !*.gitignore in it, which might be messing up the higher level declaration.

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

8 Comments

I just tested it on windows git install with gitbash, it worked fine for me. make a BRAND NEW .gitignore file somewhere and see if git status shows it when you have this in your root .gitignore (doesn't for me)
I've added a pic showing how it works for me, and a possible 'gotcha' that might be causing problems for you.
One of the 3rd party module has a .gitignore that contains a !.gitignore rule... ( could be possible that this rule is applied on entire git project instead of its [sub]directory only ? )
Apparently that is by design, each submodule controls what is tracked inside of it. So 'parent' .gitignore is only for non-module sections. stackoverflow.com/a/5127213/2801237 So why not just add an alias that adds '*.gitignore' to all modules through use of foreach. (you will have to delete each/every gitignore previously possibly )
you're misunderstooding, 3rd party modules are not git submodules but just folders with sources. however in my "modules" folder i've to exclude everything except some specific folders as i said. In 3rd party projects/folders there are some .gitignore files with !.gitignore rule that seems to affect the entire repository. Since the content of other 3rd party folders are not controlled by me, i cannot change those gitignore files.
|
1

The problem is .gitignore files within the /modules directory:

git check-ignore -v -n /modules/TC-JSON-API/storage/app/.gitignore returns: /modules/TC-JSON-API/storage/app/.gitignore:2:!.gitignore /modules/TC-JSON-API/storage/app/.gitignore

The solution then was just adding /modules/* to my .gitignore:

# exclude everything ... * # ...except !/.gitignore !*/ !/modules/wp-azth/** 

became

# exclude everything ... * modules/* # ...except !/.gitignore !*/ !/modules/wp-azth/** 

i didn't understand why git needs this kind of "specification" ...without that rule only .gitignore files of ignored folder are processed/listed in commit. However now it works.

1 Comment

This is because you exclude all files with * and then include all directories with !*/. Any .gitignore file in an included directory will be processed. By explicitly stating that modules/* be excluded you're no longer including the /modules/TC-JSON-API/storage/app/ directory, so git won't include /modules/TC-JSON-API/storage/app/.gitignore any more.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.