With git version 1.7.1, I'm trying to exclude all files except .php files.
The working solution I found relies on the command !*/
# Ignore Everything
*
# Except these files
!.gitignore
!*/
!*.php
Without the !*/
, it will only include the *.php
files in the root directory. What is !*/
doing that allows this to work?
Take a look at the documentation of gitignore
Here's my line of thinking:
The ignore statement
*
will ignore everything by default, including the root directory and all of its contents.So at this point, all files and folders in the root directory are ignored.
The
!*.php
command will re-include all the*.php
files in the root path, but the folders are still being ignored (because they don't end in.php
) - and therefore, they're not negated from the gitignore yet.So the
!*/
command re-includes all the directories (and subsequent sub-directories) so that they can be examined for*.php
files. Example:folder1/
matches the negation statement!*/
because it contains the/
at the end and the folder name fits in the wildcard operator*