[英]Git ignore except specific subdirectories
I've looked at some examples on how to ignore everything except certain sub directories like so.我看过一些关于如何忽略除某些子目录之外的所有内容的示例。
# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/*
I have also tried:我也试过:
# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/
UPDATE更新
So the code above works, however trying to exclude a directory within another directory within another does not work.所以上面的代码有效,但是试图在另一个目录中排除另一个目录中的目录不起作用。 It only works on the parent directory and sub directory.它仅适用于父目录和子目录。
# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/aaa/ddd/
After I include this in my gitingore, I run a git add --all
and I dont see any the files in git status
.在我的 gitingore 中包含这个之后,我运行了一个git add --all
并且我在git status
没有看到任何文件。
All help would be appreciated.所有帮助将不胜感激。
You have to unignore every directory in the path that you wish to unignore.您必须取消忽略要取消忽略的路径中的每个目录。 Something like the following should work in your case:类似以下的内容应该适用于您的情况:
# Ignore everything in foo
foo/*
# Except the ccc subdir
!foo/ccc
# Ignore everything in ccc subdir
foo/ccc/*
# Except the aaa subsubdir
!foo/ccc/aaa
# Ignore everything in aaa subsubdir
foo/ccc/aaa/*
# Except the ddd subsubsubdir
!foo/ccc/aaa/ddd
It's important that the ignore rules end in /*
, as that tells git to ignore everything in the folder, but not the folder itself, permitting us to add exceptions to the ignore rules for specific subdirectories.忽略规则以/*
结尾很重要,因为这告诉 git 忽略文件夹中的所有内容,而不是文件夹本身,允许我们为特定子目录的忽略规则添加例外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.