Git忽略除子文件夹之外的所有内容 [英] Git ignore all except subfolder

查看:311
本文介绍了Git忽略除子文件夹之外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过其他问题进行了搜索,但无法找到适合我的项目的工作解决方案。
有一个Magento项目,我想排除除此之外的所有内容:

  / app / design / frontend / default / theme_name#和显然所有子文件夹
/ skin / frontend / default / theme_name#和所有子文件夹

我尝试了很多组合,但没有运气。目前我坚持使用.gitignore文件:

  * 
!/ app /
!/ app / *

app / *
!/ app / design /
!/ app / design / *

但它不能在设计文件夹下递归运行。它只在我创建的设计文件夹内添加了一个测试文件。 不理解gitignore如何忽略文件夹



从中引用:


以下讨论很有帮助:
http://git.661346.n2.nabble.com /negated-list-in-gitignore-no-fun-td1675067.html
,特别是来自Linus的以下内容:



通过设计。您已选择忽略这些目录;他们
自己匹配*。因此,'git add。'不会下降到
中寻找文件。



因此,基本上每个级别你都必须去in,unignore that folder,
and ignore contents within that folder。


另外,你应该看看 .gitignore 在子目录中而不是在根目录级别,因为如果必须从根目录转到子目录级别, .gitignore 因为上面的解释,因此对于每个级别,您必须取消管理该文件夹,然后忽略内容等等。


I searched through other questions but can't find a working solution for my project. Having a Magento project, I want to exclude everything except this:

/app/design/frontend/default/theme_name # and obviously all subfolders
/skin/frontend/default/theme_name # and all subfolders

I've tried a lot of combinations but without luck. Currently I'm stuck with this .gitignore file:

*
!/app/
!/app/*

app/*
!/app/design/
!/app/design/*

But it doesn't work recursively below the design folder. It only added a test file inside the design folder that I created.

解决方案

Look at my answer here: Can't understand how gitignore ignores the folders

Quoting from that:

The following discussion was helpful: http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html , especially the following from Linus:

That's by design. You've chosen to ignore those directories; they match "*" themselves. Thus, 'git add .' doesn't descend into them looking for files.

So basically, for each level you have to go in, unignore that folder, and ignore contents within that folder.

Also, you should look at having .gitignore at subdirectory rather than at root level only as it becomes pretty complex if you have to go to the subdirectory level from the root .gitignore because of the explanation above, whereby for each level, you have to unignore the folder and then ignore the contents and so on.

这篇关于Git忽略除子文件夹之外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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