What does !*/ mean in .gitignore What does !*/ mean in .gitignore git git

What does !*/ mean in .gitignore


Take a look at the documentation of gitignore

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".


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 *