排除除 gitignore 中某些子文件夹外的所有内容无法正常工作

exclude everything but some subfolders in gitignore not working properly

请帮帮我,这应该是一些小事。我的根目录中有一个名为 "assets" 的子文件夹。它有很多子目录,我希望 GIT 只跟踪其中一个(这称为 "vendor")。资产文件夹有一个 .gitignore 文件和一个 test.txt 用于测试目的。

资产文件夹中的 .gitignore 文件如下所示:

*
!.gitignore
!vendor
!test.txt

然而,如果我输入 "git status web/assets/" 它只会跟踪 test.txt 和 .gitignore 文件本身。为什么不跟踪供应商文件夹?我也尝试过 !vendor/

请帮忙!谢谢

Why is the vendor folder not tracked?

因为该文件夹被忽略,*(忽略文件和文件夹)。
您可以通过以下方式检查:

git check-ignore -v --  web/assets/vendor/aFile

您必须先排除 vendor/ 文件夹,然后 其内容:

*
!.gitignore
!vendor/
!vendor/**
!test.txt

I want track the vendor folder and all of its already existing subfolders and files

组合 !vendor/!vendor/** 将允许您跟踪供应商文件夹及其所有现有的子文件夹和文件。