Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore gitignore files in subdirectories

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

like image 482
Joseph Avatar asked Oct 14 '25 16:10

Joseph


2 Answers

*.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.

like image 166
mawalker Avatar answered Oct 17 '25 05:10

mawalker


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.

like image 31
Joseph Avatar answered Oct 17 '25 07:10

Joseph