.gitignore 文件可以命名吗? (例如 xxx.gitignore)

Can .gitignore files be named ? (e.g. xxx.gitignore)

我想知道是否可以在存储库中包含 named .gitignore 文件,例如:

Composer.gitignore
Node.gitignore

以上两个示例都显示在 GitHub 的 gitignore template repository 中(可能有点误导)。

我已尝试将 Composer.gitignore 添加到我的存储库,但似乎该文件未被读取(我正在使用 SourceTree)。

编辑:

补充 Boldewyn 未直接回答问题的相关信息:

The page's README says:

A Collection of .gitignore templates and that's what it is: Only templates. If you want to use one, pick it, drop it in your repository and rename it to .gitignore.

git recognizes only two places for listing ignored files: .gitignore files in a folder/subfolder and the file .git/info/ignore. See git help gitignore for in-depth information.

页面的自述文件说:

A Collection of .gitignore templates

就是这样:只有模板。如果您想使用一个,请选择它,将其放入您的存储库并将其重命名为 .gitignore.

git 仅识别两个用于列出忽略文件的位置:folder/subfolder 中的 .gitignore 个文件和 .git/info/ignore 文件。有关详细信息,请参阅 git help gitignore

使文件 将 .gitignore 命名为 .gitignore 文件的唯一方法是:

  • 直接引用

    git config --global core.excludesfile ~/myfile.gitignore
    
  • 通过smudge script from a content filter driver生成它。
    第二个选项有点复杂,但会处理所有版本化的 <file>.gitignore 并生成最终的 .gitignore.

除了这两个选项,.gitignore man page 不允许任何其他命名约定。