Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore to ignore all files, then recursively allows files of a certain type

I have a folder that is purely a T4 template folder but it outputs code generated files into other directories. So I'm looking to ignore everything except *.tt files (i.e. the *.cs, *.master, *.resx, etc.). There is one gotcha. I have a subfolder called static that contains files that should never be ignored.

/Test.tt
/Test.cs
/TestHtml.tt
/TestHtml.html
/Static
   /Sub/Sub.cs
   /Sub/Sub2/Sub2.cs
   /Sub3/Sub4/Sub5/Sub5.html

I only want to ignore the /Test.cs and /Test.html but include all other files. I've tried the following:

/.gitignore

# Ignore all
*

# But not these files...
!.gitignore
!*.tt

/Static/.gitignore

!*.*
#also have just tried blank

I can't get git to ignore the right things...main problem is the 'recursive exclude' I want for Static/..

like image 575
Terry Avatar asked Dec 16 '22 14:12

Terry


1 Answers

You need to anchor your * otherwise it will continue to match all files even in un-ignored directories.

e.g.

/*

!.gitignore
!*.tt
!/Static/
like image 177
CB Bailey Avatar answered Dec 19 '22 06:12

CB Bailey