.gitignore白名单上的目录及其内容 [英] .gitignore whitelist on directory and its contents

查看:2031
本文介绍了.gitignore白名单上的目录及其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ vendor中的原始.gitignore文件看起来像这样:

我试图在我的Zend Framework 2供应商目录中将目录(及其内容)SupplierName列入白名单。这:

 #在这里添加供应商路径白名单
#例如:作曲家目录写在这里!composer (不含引号)
!.gitignore
*

喜欢将目录供应商名称列入白名单,我认为这应该不会太难。我有阅读gitignore上的文档并尝试了以下配置:



首先尝试,在评论后面添加!SupplierName,表示必须在此添加白名单路径。

 #在这里添加要列入白名单的供应商路径
!供应商名称
#例如:作曲家目录写在这里!composer(不含引号)
!.gitignore
*

之后,我执行 git status ,它没有显示vendor / SupplierName目录。 git add vendor / SupplierName 显示以下消息:
$ b


以下路径将被忽略您的.gitignore文件之一:供应商/供应商名称

第二次尝试

 #在此处添加要列入白名单的供应商路径
#例如:作曲家目录写在这里!composer(不含引号)
!SupplierName
!.gitignore
*

之后我执行 git status ,它没有显示vendor / SupplierName目录。 git add vendor / SupplierName 显示以下消息:
$ b


以下路径将被忽略您的.gitignore文件之一:供应商/供应商名称

第三次尝试

 #在此处添加要列入白名单的供应商路径
#例如:作曲家目录写在这里!composer(不含引号)
!.gitignore
*
!供应商名称

紧接着我执行 git status ,它没有显示vendor / SupplierName目录。 git add vendor / SupplierName 似乎正常工作。但是现在,当我想添加Module.php文件(以及一些其他文件,子目录等)时,会发生以下情况。 git add vendor / SupplierName / Module.php - >


被一个.gitignore文件忽略:vendor / SupplierName / Module.php




 #添加供应商路径白名单
#例如:作曲家目录写在这里!composer(不含引号)
*
!.gitignore
!供应商名称
!供应商名称/
!供应商名称/ *

允许我直接在vendor / SupplierName ,但是 git add vendor / SupplierName / config / module.config.php 仍然会导致


以下路径会被一个.gitignore文件忽略:vendor / SupplierName / config / module.config.php

我一直在寻找有关递归白名单的问题,因为这似乎是问题,但没有出现。

解决方案

您可以使用2 .gitignore 文件来达到理想效果:

 #vendor / .gitignore 

!.gitignore
!供应商名称/
!供应商名称/ *

#供应商/供应商名称/ .gitignore
!*

我用一个测试回购测试了这个功能,似乎对我来说可以在 vendor / SupplierName 目录。

  $ git add。 

$ git status
#在分支主机上
#要提交的更改:
#(使用git reset HEAD< file> ... )

#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
#新文件: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 / Supp lierName / dir3 / dir6 / f7
#new file:vendor / SupplierName / dir3 / dir7 / f8
#new file:vendor / SupplierName / e


I'm trying to whitelist the directory (and its contents) SupplierName in my Zend Framework 2 vendor directory.

The original .gitignore file in /vendor looks like this:

# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*

Now I'd like to whitelist the directory SupplierName which shouldn't be too hard I thought. I have read the docs on gitignore and tried the following configurations:

First try, add !SupplierName right after the comment which says that I have to add the whitelisted path here.

# Add here the vendor path to be whitelisted
!SupplierName
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*

Right after that I executed git status which didn't show the vendor/SupplierName directory. git add vendor/SupplierName showed the following message:

The following paths are ignored by one of your .gitignore files: vendor/SupplierName

Second try

# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!SupplierName
!.gitignore
*

Right after that I executed git status which didn't show the vendor/SupplierName directory. git add vendor/SupplierName showed the following message:

The following paths are ignored by one of your .gitignore files: vendor/SupplierName

Third try

# Add here the vendor path to be whitelisted
# Ex: for composer directory write here "!composer" (without quotes)
!.gitignore
*
!SupplierName

Right after that I executed git status which didn't show the vendor/SupplierName directory. git add vendor/SupplierName seems to work. But now, when I want to add the Module.php file (and some other files, subdirectories, etc) the following happens. git add vendor/SupplierName/Module.php -->

The following paths are ignored by one of your .gitignore files: 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/*

Allows me to add files directly in vendor/SupplierName, but git add vendor/SupplierName/config/module.config.php still results in

The following paths are ignored by one of your .gitignore files: vendor/SupplierName/config/module.config.php

I've been searching for problems regarding recursive whitelisting, because that seems to be the problem, but nothing came up.

解决方案

You can use 2 .gitignore files to achieve the desired result:

# vendor/.gitignore
*
!.gitignore
!SupplierName/
!SupplierName/*

# vendor/SupplierName/.gitignore
!*

I tested this with a test repo and seems to work for me in adding files as many levels deep underneath the vendor/SupplierName directory.

$ 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
#

这篇关于.gitignore白名单上的目录及其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆