-1

I've set .gitignore file with the following lines

This are working:

application/cache/*
!application/cache/index.html

But this doesn't work:

web/uploads/*
!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep

There is no /web/uploads or web/uploads/filters/.gitkeep,web/uploads/payments/.gitkeep or web/uploads/surveys/.gitkeep files.

Hris
  • 153
  • 13
afdi2
  • 89
  • 10
  • Possible duplicate of [.gitignore exclude folder but include specific subfolder](https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder) – phd Jul 04 '18 at 12:44
  • You need to unignore subdirectories: `!web/uploads/filters/` and so on. – phd Jul 04 '18 at 12:44

1 Answers1

5

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
axiac
  • 68,258
  • 9
  • 99
  • 134