简体   繁体   中英

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.

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-

* !*.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:

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)

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 .

Nguyễn Thái Ngọc Duy ( pclouds ) is trying to add this feature:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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