我有一个文件夹,根据我的.gitignore不应该忽略它,但是git仍然忽略它。我找不到其他任何建议忽略此文件夹的.gitignore文件或git配置,并且git check-ignore
没有打印任何内容。
我的.gitignore的组织方式很像白名单:
*
!.gitignore
!NotIgnoredFolder/
!SomeOtherFolderInRoot
我有一个沿着NotIgnoredFolder/subfolder/js的文件夹,而git正在忽略它。根据其位置和我的.gitignore,显然不应忽略此路径。当我尝试使用
git add NotIgnoredFolder/subfolder/js
添加它时,我得到The following paths are ignored by one of your .gitignore files:
NotIgnoredFolder/subfolder/js
我已经在整个C:驱动器中搜索了可能会干扰但不走运的.gitignore和.gitignore_global文件。我还检查了.git/config和.git/info/exclude。此外,当我尝试
git check-ignore NotIgnoredFolder/subfolder/js
时,Git打印一个空行。有什么方法可以查看导致忽略的.gitignore文件吗?还是这是我设置gitignore的方式的结果?
我尝试过的没有成功的解决方案:
Git is ignoring files that aren't in gitignore
Git is ignoring .idea folder, but that isn't in gitignore
which gitignore rule is ignoring my file
最佳答案
Git跟踪文件,而不是目录,但是gitignore规则可以匹配文件和目录。试试这个:
# Ignore by default
*
!.gitignore
# Whitelist the folder
!NotIgnoredFolder/
# Recursively whitelist its contents
!NotIgnoredFolder/**
如果您不将目录列入白名单,则git不会进入该目录,但是如果您不使用
**
(或*
,如果您特别不想递归地将其列入白名单)将内容列入白名单,则它将忽略目录中的文件。目录。人们还可以做其他事情:在顶部使用
/*
而不是*
在默认情况下仅排除顶级项目,或者使用!*/
将所有目录列入白名单(但不一定包含其中的文件)。具体来说,!*/
将使!NotIgnoredFolder/
行不必要,因为它将允许下降到任何目录。但我相信以上内容是最适合您的情况的。