I have one directory tree with many kind of different files. There are 300 directories on the parent directory. Each directory could have other sub directories.
I only want to track *.cocci on all sub directories. Here is my .gitignore:
*
!*.cocci
But it do not work, as the files on sub directories are not tracked. How can I tell git that I only want to track *.cocci on all sub directories?
It is impossible to unignore directory by
!dir
in .gitignore, but then it is still possible to add directory by hand:So if the .gitignore file looks like:
Then when you do
git add .
new*.txt
files are then added. New directory will not be auto-added, it have to be added by hand bygit add dir -f
Read this question.
You want:
Note, this'll track only
*.cocci
files. Yours doesn't work because you ignore everything (that's the first line), which ignores all subdirectories.Have you tried
!*/*.cocci
instead of your!*.cocci
?To extend @simont answer, if we wanted to whitelist
*.cocci
files of a given directory and its subdirectories I would wrongly have entered:That seems not to be including
*.cocci
files underdirectory/subtree
.In order to find all
*.cocci
files in all sub-directories ofdirectory
entered the following: