[英]Ignore Everything Except a Series of Different Files in Different Directories
Following on from these questions: 接下来是这些问题:
I'm struggling to implement this in my own environment. 我正在努力在自己的环境中实现这一目标。
I've followed the advice and adapted it to my own needs, however, when I run git status
all I get as untracked is the .gitignore itself. 我已经遵循了建议并将其调整为适合自己的需求,但是,当我运行
git status
得到的所有内容都是.gitignore本身,因为未跟踪。
I'm creating a Magento Module, which, if you've every created one, you'll know has files in odd locations throughout the Magento installation. 我正在创建一个Magento模块,如果每个模块都创建了一个模块,那么在整个Magento安装过程中,您会知道文件位于不同的位置。
Here's the .gitignore I created: 这是我创建的.gitignore:
# Ignore All
/*
/*/
# EXCEPT
# =============
# This
!/.gitignore
# Module Config
!/app/etc/modules/Company_Module.xml
# Module Code
!/app/code/local/Company/Module/
# Front End Design
!/app/design/frontend/base/default/layout/company_module.xml
!/app/design/frontend/base/default/template/company_module/
# Back End Design
!/app/design/adminhtml/default/default/layout/company_module.xml
!/app/design/adminhtml/default/default/template/company_module/
# JavaScript
!/js/company_module/
# Front End Skin
!/skin/frontend/base/default/css/company_module/
!/skin/frontend/base/default/images/company_module/
!/skin/frontend/base/default/js/company_module/
# Back End Skin
!/skin/adminhtml/default/default/css/company_module/
!/skin/adminhtml/default/default/images/company_module/
!/skin/adminhtml/default/default/js/company_module/
I created the following file to test its validity /app/etc/modules/Company_Module.xml
but it's not appearing at all within the git status
output. 我创建了以下文件来测试其有效性
/app/etc/modules/Company_Module.xml
但它根本没有出现在git status
输出中。
I'm not sure what to do at this point. 我目前不确定该怎么办。
Okay, I've worked out how this should be structured. 好的,我已经弄清楚了应该如何组织它。
I have to treat each folder as it's own entity whilst creating the file. 创建文件时,我必须将每个文件夹视为自己的实体。 For example, I'll look at the root and use
/*
to ignore all, then go through each folder within this directory and negate what I need to negate, including negations only for the folders I want to negate. 例如,我将查看根目录并使用
/*
忽略所有内容,然后遍历此目录中的每个文件夹并否定我需要否定的内容,包括仅对要否定的文件夹进行否定。 Instead of tracing the full paths for the files, I'd treat it on a folder by folder basis. 与其跟踪文件的完整路径,不如逐个文件夹地处理它。 See the below example:
请参见以下示例:
/*
!/app
app/*
!/app/etc
app/etc/*
!app/etc/modules
app/etc/modules/*
!/app/etc/modules/Company_Module.xml
Line by line: 逐行:
/*
/*
!/app
!/app
app/*
app/*
!/app/etc
!/app/etc
app/etc/*
app/etc/*
!/app/etc/modules
!/app/etc/modules
app/etc/modules/*
app/etc/modules/*
!/app/etc/modules/Company_Module.xml
!/app/etc/modules/Company_Module.xml
It's a little long-winded but it sure beats adding 400+ lines for ignoring each irrelevant file/folder. 这有点麻烦,但是肯定可以添加400多个行来忽略每个不相关的文件/文件夹。
I've structured the file this way, and it's expanded from 36 lines to 91 so it's not too bad. 我以这种方式构造了文件,它从36行扩展到91行,所以还算不错。 Everything has now been committed and pushed to my repo with this
.gitignore
structure and I can confirm it's validity. 现在,所有内容都已提交,并使用此
.gitignore
结构推送到我的存储库中,我可以确认它的有效性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.