gpt4 book ai didi

git - .gitignore 目录及其内容的白名单

转载 作者:IT王子 更新时间:2023-10-29 00:59:29 32 4
gpt4 key购买 nike

我正在尝试将我的 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 显示以下消息:

The following paths are ignored by one of your .gitignore files: 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 显示以下消息:

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

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/*

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

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

关于git - .gitignore 目录及其内容的白名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288712/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com