gitignore 匹配子目录中带有前缀和后缀的文件
我喜欢只跟踪以“es”开头并以 *.h 或 *.m 结尾的文件,
所以我尝试了以下方法:
#exlude all
*
#except
!es*.h
!es*.m
但
#exlude all
*
#except
!*/es*.h
!*/es*.m
两者都不适用于子目录中的文件
I like to track only files that start with "es" and end with *.h or *.m
so i tried this:
#exlude all
*
#except
!es*.h
!es*.m
and
#exlude all
*
#except
!*/es*.h
!*/es*.m
but neither works for files in subdirectories
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您忽略所有内容 (
*
) 时,您会忽略文件夹,即使它们也有内容,因为*
匹配所有内容。如果您忽略某些内容,则该内容将仅与根目录的文件匹配。如果您需要取消忽略某个目录,则需要明确说明(即
!mydir/
)。但这会忽略该目录的所有内容,因此您必须重新定义该目录内容的忽略/忽略模式。即使您这样做,如果您尚未将目录添加到索引中,您也不会在git status
中看到它。你的案子很容易解决,但模式却颠倒了。
您基本上想要做的是忽略所有
es
开头且.h
或 结尾的 内容> <代码>.m。这样做:
正如您在最后一个命令中看到的,我已经反转了您的模式以忽略所有不以
e
开头且后面不跟s
的内容,并且不以.h
或.m
结尾,并且也未忽略目录。即使目录有更多内容,它也会被忽略,因为它与模式匹配,并且只添加了想要的部分。编辑:已更新
When you ignore everything (
*
), you ignore folders, even if they have contents too, as*
matches everything.If you unignore something, that would be matched only for the files of the root dir. If you need to unignore a directory, you need to explicitly say that (ie
!mydir/
). But that would unignore all the contents of that dir, so you'd have to redefine the ignore/unignore pattern for the contents of that dir. Even if you do that, if you haven't already added the dir to the index, you won't see that ingit status
.Your case can be solved easily but inverting the pattern.
What you basically want to do is ignore everything that
es
and.h
or.m
.So do that:
As you see in the last command, I've inverted your pattern to ignore everything that doesn't start with
e
and is not followed by ans
and that doesn't end with.h
or.m
and also unignored a dir. Even though the dir had more content, it was ignored as it matched the pattern, and only the wanted parts were added.edit: updated