简体   繁体   English

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

[英]gitignore - Ignore all file types except specified ones

I only want to commit files which extension is .fmb , .fmx and .pll , but I can't configure .gitignore file to achieve this. 我只想提交扩展名为.fmb.fmx.pll ,但我无法配置.gitignore文件来实现此目的。

I've tried with the following: 我试过以下内容:

!.fmb
!.fmx
!.pll

and also with: 还有:

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

but it doesn't work. 但它不起作用。

Try this in your gitignore file- 在你的gitignore文件中试试这个 -

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

You will want to first ignore everything and then whitelist files. 您将首先忽略所有内容然后将文件列入白名单。

The only rule to remember when dealing with gitignore rules is: 处理gitignore规则时要记住的唯一规则是:

It is not possible to re-include a file if a parent directory of that file is excluded ( * ) 如果排除该文件的父目录,则无法重新包含文件*
( * : unless certain conditions are met in git 2.?+, see below) * :除非在git 2.?+中满足某些条件,见下文)

Since ' * ' would ignore folders as well, any file exclusion rule would not be working. 由于' * '也会忽略文件夹,因此任何文件排除规则都不起作用。

Try: 尝试:

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

That will properly un-ignore the folders ( !*/ ), and allow the next exclusion rule to work on files. 这将正确地取消忽略文件夹( !*/ ),并允许下一个排除规则处理文件。


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included . 请注意,使用git 2.9.x / 2.10(2016年中期?), 如果在重新包含的路径中没有通配符 ,则可以重新包含该文件的文件。

Nguyễn Thái Ngọc Duy ( pclouds ) is trying to add this feature: NguyễnTháiNgọcDuy( pclouds正在尝试添加此功能:

However, since one of the condition to re-inclusion was: 但是,由于重新纳入的条件之一是:

The directory part in the re-include rules must be literal (ie no wildcards) 重新包含规则中的目录部分必须是文字(即没有通配符)

That would not have worked here anyway. 无论如何,这不会在这里奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM