.gitignore忽略所有文件,然后递归地允许某种类型的文件 [英] .gitignore to ignore all files, then recursively allows files of a certain type

查看:362
本文介绍了.gitignore忽略所有文件,然后递归地允许某种类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个纯粹是T4模板文件夹的文件夹,但它将代码生成的文件输出到其他目录中。所以我打算忽略除* .tt文件(即* .cs,* .master,*。resx等)以外的所有内容。有一个问题。

  /Test.tt 
/ Test。我有一个名为static的子文件夹,其中包含永远不应被忽略的文件。 cs
/TestHtml.tt
/TestHtml.html
/ Static
/Sub/Sub.cs
/Sub/Sub2/Sub2.cs
/ Sub3 / Sub4 / Sub5 / Sub5.html

仅限 要忽略/Test.cs和/Test.html,但包含所有其他文件。我试过以下内容:

/。gitignore

 #忽略所有
*

#但不是这些文件...
!.gitignore
!*。tt

/Static/.gitignore

 !*。* 
#也试过空白

我无法让git忽略正确的东西...主要问题是'我想为静态/ 。'递归排除'。

解决方案

您需要定位 * ,否则它将继续匹配所有文件,即使在未被忽略的目录中也是如此。



例如

  / * 

!.gitignore
!*。tt
! / Static /


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/..

解决方案

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

e.g.

/*

!.gitignore
!*.tt
!/Static/

这篇关于.gitignore忽略所有文件,然后递归地允许某种类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆