简体   繁体   中英

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

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

显示* .gitignore有效


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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM