Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore - Ignore all file types except specified ones

Tags:

git

gitignore

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.

like image 674
Julen Avatar asked Oct 05 '15 13:10

Julen


2 Answers

Try this in your gitignore file-

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

You will want to first ignore everything and then whitelist files.

like image 119
Harish Ved Avatar answered Oct 14 '22 03:10

Harish Ved


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:

  • commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
  • commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.

However, since one of the condition to re-inclusion was:

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

That would not have worked here anyway.

like image 5
VonC Avatar answered Oct 14 '22 03:10

VonC