我正在尝试将Zend Framework 2供应商目录中的目录(及其内容)SupplierName列入白名单。
/ vendor中的原始.gitignore文件如下所示:
# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*
现在,我想将目录SupplierName列入白名单,我认为这应该不会太难。我有read the docs on gitignore并尝试了以下配置:
首先尝试,在注释之后添加!SupplierName,它说我必须在此处添加白名单路径。
# Add here the vendor path to be whitelisted
!SupplierName
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*
在那之后,我执行了
git status
,它没有显示vendor / SupplierName目录。 git add vendor/SupplierName
显示以下消息:第二次尝试
# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!SupplierName
!.gitignore
*
在那之后,我执行了
git status
,它没有显示vendor / SupplierName目录。 git add vendor/SupplierName
显示以下消息:第三次尝试
# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*
!SupplierName
在那之后,我执行了
git status
,它没有显示vendor / SupplierName目录。 git add vendor/SupplierName
似乎可以工作。但是现在,当我想添加Module.php文件(以及其他一些文件,子目录等)时,会发生以下情况。 git add vendor/SupplierName/Module.php
-># Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
*
!.gitignore
!SupplierName
!SupplierName/
!SupplierName/*
允许我直接在vendor / SupplierName中添加文件,但是
git add vendor/SupplierName/config/module.config.php
仍然会导致我一直在寻找有关递归白名单的问题,因为这似乎是问题所在,但是什么也没发生。
最佳答案
您可以使用2个.gitignore
文件来获得所需的结果:
# vendor/.gitignore
*
!.gitignore
!SupplierName/
!SupplierName/*
# vendor/SupplierName/.gitignore
!*
我使用测试存储库对此进行了测试,似乎可以为我添加许多文件(位于
vendor/SupplierName
目录下)。$ git add .
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: vendor/.gitignore
# new file: vendor/SupplierName/.gitignore
# new file: vendor/SupplierName/a
# new file: vendor/SupplierName/b
# new file: vendor/SupplierName/c
# new file: vendor/SupplierName/d
# new file: vendor/SupplierName/dir1/d
# new file: vendor/SupplierName/dir1/dir4/dir5/dir6/dir7/dir8/dir9/dir10/somefile
# new file: vendor/SupplierName/dir1/dir4/f1
# new file: vendor/SupplierName/dir1/dir4/f2
# new file: vendor/SupplierName/dir1/dir4/f3
# new file: vendor/SupplierName/dir1/dir4/f4
# new file: vendor/SupplierName/dir1/e
# new file: vendor/SupplierName/dir1/f
# new file: vendor/SupplierName/dir3/dir6/f5
# new file: vendor/SupplierName/dir3/dir6/f6
# new file: vendor/SupplierName/dir3/dir6/f7
# new file: vendor/SupplierName/dir3/dir7/f8
# new file: vendor/SupplierName/e
#