问题
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/..
回答1:
You need to anchor your * otherwise it will continue to match all files even in un-ignored directories.
e.g.
/*
!.gitignore
!*.tt
!/Static/
回答2:
Something like:
/*
!.gitignore
!*.tt
!/Static/
should work.
Look at my answer below for making it more complex when you want to unignore a subdirectory within some other folder when you are ignoring everything else.
Can't understand how gitignore ignores the folders
来源:https://stackoverflow.com/questions/5876075/gitignore-to-ignore-all-files-then-recursively-allows-files-of-a-certain-type