gitignore - 忽略除指定文件之外的所有文件类型

gitignore - Ignore all file types except specified ones

我只想提交扩展名为 .fmb.fmx.pll 的文件,但我无法配置 .gitignore 文件来实现此目的。

我试过以下方法:

!.fmb
!.fmx
!.pll

还有:

!*.fmb
!*.fmx
!*.pll

但是没用。

在你的 gitignore 文件中试试这个 -

* !*.fmb !*.fmx !*.pll

您需要先忽略所有内容,然后将文件列入白名单。

在处理 gitignore 规则时要记住的唯一规则是:

It is not possible to re-include a file if a parent directory of that file is excluded (*)
*:除非在git 2.?+中满足某些条件,见下文)

由于“*”也会忽略文件夹,因此任何文件排除规则都不起作用。

尝试:

*
!*/
!*.fmb
!*.fmx
!*.pll

这将正确地取消忽略文件夹 (!*/),并允许下一个排除规则对文件起作用。


请注意,对于 git 2.9.x/2.10(2016 年年中?),如果排除了该文件的父目录,则可能会重新包含该文件 if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) 正在尝试添加此功能:

但是,由于重新收录的条件之一是:

The directory part in the re-include rules must be literal (i.e. no wildcards)

无论如何,这在这里是行不通的。