There is a big difference between the rules that work and those that do not work. Those that work operate on a top-level directory and a file inside it. Those that do not work contain intermediate directories.
web/uploads/*
This ignore rule tells Git to ignore all the files and subdirectories of web/uploads
.
The exclusion rules that follow it:
!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep
do not match any files because the filters
, payments
and surveys
directories (and their content) are ignored because of the previous rule.
There is no simple solution for this problem (or, at least, none that I am aware of).
A solution exists (but it is verbose): you have to tell Git to ignore everything in web/uploads
except for the filters
, payments
and surveys
subdirectories then, for each of them to ignore everything inside it except for .gitkeep
.
As .gitignore
rules, the paragraph above is represented as follows:
# Ignore everything in web/uploads
web/uploads/*
# ... except for the 'filters' subdirectory...
!web/uploads/filters
# ... but ignore everything inside it...
web/uploads/filters/*
# ... except for .gitkeep
!web/uploads/filters/.gitkeep
# The same rules as above for 'payments'
!web/uploads/payments
web/uploads/payments/*
!web/uploads/payments/.gitkeep
# ... and surveys
!web/uploads/surveys
web/uploads/surveys/*
!web/uploads/surveys/.gitkeep