How to make 'git not ignore' the extension of a specific file in the subfolder structure?

Let's 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 just want to not ignore *.c.

I tried

*                                                                         
!*.c 

in .gitignore, but it only works at the current level.

I want to install something like !*/*/*.c, since later there may be other directories added to the git repository, I cannot write the file hard .gitignore.

+4
source share
2 answers

Add !*/to your .gitignoredirectory to allow directories:

*
!*/
!*.c

From the gitignore man page (my attention):

"!" ; , , . , . Git , , , . ( "\" ) "!" , "!" , , "! important!.txt".

.

+4

GITIGNORE(5):

"!" ; , , . , .

, , , /example.c , /a/b/d.c - , /a /a/b.

, , .gitignore:

*
!*/
!*.c
+1

All Articles