.gitignore 排除文件夹但包含特定的子文件夹 [英] .gitignore exclude folder but include specific subfolder
问题描述
我有文件夹 application/
,我将它添加到 .gitignore
.application/
文件夹内是文件夹 application/language/gr
.如何包含此文件夹?
I have the folder application/
which I add to the .gitignore
. Inside the application/
folder is the folder application/language/gr
. How can I include this folder?
我已经试过了
application/
!application/language/gr/
没有运气...
推荐答案
如果您排除 application/
,那么它下面的所有内容都将始终被排除(即使某些后来的否定排除模式(unignore")) 可能与 application/
下的内容匹配.
If you exclude application/
, then everything under it will always be excluded (even if some later negative exclusion pattern ("unignore") might match something under application/
).
为了做你想做的事,你必须忽略"你想要忽略"的任何东西的每个父目录.通常你最终会成对地为这种情况编写规则:忽略目录中的所有内容,但不忽略某些特定的子目录.
To do what you want, you have to "unignore" every parent directory of anything that you want to "unignore". Usually you end up writing rules for this situation in pairs: ignore everything in a directory, but not some certain subdirectory.
# you can skip this first one if it is not already excluded by prior patterns
!application/
application/*
!application/language/
application/language/*
!application/language/gr/
注意
尾随的 /*
很重要:
- 模式
dir/
排除了一个名为dir
的目录以及(隐式地)它下的所有内容.
使用dir/
,Git 永远不会查看dir
下的任何内容,因此永远不会将任何取消排除"模式应用于dir下的任何内容代码>.
- 模式
dir/*
没有说明dir
本身;它只是排除dir
下的所有内容.使用dir/*
,Git 将处理dir
的直接内容,让其他模式有机会取消排除"某些内容(!dir/sub/
).
- The pattern
dir/
excludes a directory nameddir
and (implicitly) everything under it.
Withdir/
, Git will never look at anything underdir
, and thus will never apply any of the "un-exclude" patterns to anything underdir
. - The pattern
dir/*
says nothing aboutdir
itself; it just excludes everything underdir
. Withdir/*
, Git will process the direct contents ofdir
, giving other patterns a chance to "un-exclude" some bit of the content (!dir/sub/
).
这篇关于.gitignore 排除文件夹但包含特定的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!