简体   繁体   English

忽略除不同目录中的一系列不同文件以外的所有内容

[英]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: 逐行:

  1. Ignore every file in root - /* 忽略根目录中的每个文件- /*
  2. Except the app folder - !/app 除了app文件夹- !/app
  3. Within the app folder, ignore all files - app/* 在app文件夹中,忽略所有文件app/*
  4. Except the etc folder - !/app/etc 除了etc文件夹- !/app/etc
  5. Within the etc folder, ignore all files - app/etc/* 在etc文件夹中,忽略所有文件app/etc/*
  6. Except the modules folder - !/app/etc/modules 除了modules文件夹- !/app/etc/modules
  7. Within the modules folder, ignore all files - app/etc/modules/* 在modules文件夹中,忽略所有文件app/etc/modules/*
  8. Except the module configuration file - !/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.

相关问题 如何忽略除顶级目录中的几个文件以及.gitignore的几个目录中的所有内容之外的所有内容 - How do I ignore everything except a couple files in the top-level directory and everything in a few directories with .gitignore 使.git-ftp-ignore忽略所有内容,除了一些文件/目录 - Make .git-ftp-ignore ignore everything except a few files / directories git忽略除某些子目录中的文件以外的所有内容 - git ignore everything except files in certain subdirectories Make.gitignore 忽略除少数文件外的所有内容 - Make .gitignore ignore everything except a few files 如何忽略除两个目录(嵌套)之外的所有内容? - How can I ignore everything except two directories (nested)? 忽略根目录中的所有文件,但某些特定文件,目录除外 - Ignore all the files in the root except for some particular files, directories GIT:忽略除子子目录和某些文件以外的所有内容 - GIT: ignore everything except sub-subdirectory and some files gitignore:忽略子文件夹中的所有内容,但具有特定扩展名的文件除外 - gitignore: Ignore everything from subfolder except files with specific extensions 除了几个文件,我如何忽略我回购中的所有内容? - How do I ignore everything in my repo except a few files? 如果文件位于其他目录中,则将项目保存在Git中 - Save a project in Git, if files are located in different directories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM