Configure git to track only one file extension
Read this question.
You want:
# Blacklist everything*# Whitelist all directories!*/# Whitelist the file you're interested in. !*.cocci
Note, this'll track only *.cocci
files. Yours doesn't work because you ignore everything (that's the first line), which ignores all subdirectories.
To extend @simont answer, if we wanted to whitelist *.cocci
files of a given directory and its subdirectories I would wrongly have entered:
directory/*!directory/*/!directory/*.cocci
That seems not to be including *.cocci
files under directory/subtree
.
In order to find all *.cocci
files in all sub-directories of directory
entered the following:
directory/**!directory/*/!directory/**/*.cocci
It is impossible to unignore directory by !dir
in .gitignore, but then it is still possible to add directory by hand:
git add dir -f
So if the .gitignore file looks like:
*!*.txt
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 by git add dir -f