.gitignore: Correctly specifying ignore and exclude patterns
I was trying to make git ignore some directories but exclude certain file and directories within it. My directory structure was as follows:
. └── public ├── index.php └── typo3conf ├── AdditionalConfiguration.Development.php ├── AdditionalConfiguration.php ├── LocalConfiguration.php ├── PackageStates.php └── ext ├── typo3_base_setup └── site_package
I wanted git to ignore everything in public except LocalConfiguration.php, AdditionalConfiguration.php and site_package. My first try looked like this:
/public/* !/public/typo3conf/LocalConfiguration.php !/public/typo3conf/AdditionalConfiguration.php !/public/typo3conf/ext/site_package
But..., that did not work. Git ignored the hole public sub tree. After reading the gitignore documentation and some try and error I came up with a working solution:
/public/* !/public/typo3conf /public/typo3conf/* !/public/typo3conf/LocalConfiguration.php !/public/typo3conf/AdditionalConfiguration.php !/public/typo3conf/ext /public/typo3conf/ext/* !/public/typo3conf/ext/site_package
It looks like, you have to explicitely specify the exclude (un-ignore) pattern for each directory level. I'm not sure, if this is a bug or not, but it took me a while to figure it out.