What does !*/ mean in .gitignore

跟風遠走 提交于 2019-12-22 01:54:02

问题


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?


回答1:


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".




回答2:


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 *



来源:https://stackoverflow.com/questions/25554504/what-does-mean-in-gitignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!