Say I have a folder structure like this:
├── a
│ ├── b
│ │ ├── c.xml
│ │ └── d.c
│ ├── v
│ ├── e.class
│ └── g.c
|
├── m
│ ├── p
│ │ ├── w.out
│ │ └── x.c
│ ├── q
│ │ ├── y.mp3
│ │ └── z.c
And I only want to not ignore *.c
.
I tried
*
!*.c
in .gitignore
, but that seems only work in the current level.
What I want is to set something like !*/*/*.c
, since there may be other directories added to the git repo later, I can't hard-code the .gitignore
file.
Add !*/
to your .gitignore
to allow directories:
*
!*/
!*.c
From gitignore man page (emphasis mine):
An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".
That's why you have to exclude the directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With