Reputation: 35973
I am aware this was asked here and answered, however no answer covers when the ignoring line uses wildcards...
I have the following line in .gitignore:
**/_secrets
Now I would like to add one exception to this using the !
syntax:
!**/_secrets/not_a_secret.txt
However this does not seem to work.
What I've tried:
!**/not_a_secret.txt
!**/_secrets/not_a_secret.txt
!(**/_secrets/not_a_secret.txt)
I've also tried to change **/_secrets
to **/_secrets/
still does not work, all files in the _secrets folder are ignored, with no exception of not_a_secret.txt file.
What am I missing?
Upvotes: 2
Views: 1014
Reputation: 1329092
The general rule of gitignore is simple:
It is not possible to re-include a file if a parent directory of that file is excluded.
To exclude files (or all files) from a subfolder of an ignored folder f
, you would do:
**/_secrets/
!**/_secrets/**/
!**/_secrets/**/not_a_secret.txt
Meaning: you need to whitelist folders first, before being able to exclude from gitignore
files.
Upvotes: 2