下面这些取反的export-ignore模式为什么不起作用?

编程语言 2026-07-09

在一个 .gitattributes 文件中定义被否定的export-ignore(s) 时,如下所示:

* export-ignore

composer.json              -export-ignore
bin/lean-package-validator -export-ignore
resources/                 -export-ignore
src/                       -export-ignore

我在想,通过 git archive -o test-archive.zip HEAD 创建归档时,它似乎没有起作用。

让它起作用,也就是生成预期的dist产物文件,唯一能做到的方法,是通过以下被否定的export-ignore(s):

* export-ignore

composer.json              -export-ignore
bin/                       -export-ignore
bin/lean-package-validator -export-ignore
resources/                 -export-ignore
resources/**               -export-ignore
src/                       -export-ignore
src/**                     -export-ignore

这是个Bug吗?

解决方案

它在 文档 的开头就写明了原因:

The rules by which the pattern matches paths are the same as in  .gitignore  files  (see  gitig‐
     nore(5)), with a few exceptions:
•   negative patterns are forbidden
•   patterns that match a directory do not recursively match paths inside that directory (so us‐
    ing the trailing-slash path/ syntax is pointless in an attributes file; use path/** instead)
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章