git:忽略除一个文件夹以外的所有文件夹的子文件夹

发布于 2025-02-12 05:18:13 字数 383 浏览 0 评论 0原文

当前我有一个看起来像这样的存储库:

Git-Repository
└─── A
│  └─── X
│  └─── Y
└─── B
│  └─── X
│  └─── Y
└─── C
│  └─── X
│  └─── Y
│ ....

我想以某种方式编辑我的 .gitignore 文件忽略所有x子目录以外的所有x子目录。

这是我真正的回购的简单版本。实际上,我还有更多的文件夹和子文件夹,所以我无法一个一个目录。

edit1: 这是我想做的,但不起作用。 x子目录被忽略了,但是“ c”中的一个不是“ unignored”“”

X/
!C/X/*

currenty I have an repository that looks like this:

Git-Repository
└─── A
│  └─── X
│  └─── Y
└─── B
│  └─── X
│  └─── Y
└─── C
│  └─── X
│  └─── Y
│ ....

I want to edit my .gitignore file to somehow ignore all X subdirectories except the one in C directory.

It is important to mention that this is a simple version of my real repo. I actually have a LOT more folders and subfolders, so I cant set all the directories one by one.

Edit1:
This is what I am trying to do, but not working.
X subdirectory is being correcyly ignored, but the one in "C" isnt ""unignored""

X/
!C/X/*

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2025-02-19 05:18:13

gitignore docs

如果在模式的开头或中间(或两者)都有一个分离器,则该模式相对于特定的.gitignore文件本身的目录级别。

这意味着X/仅匹配顶级X目录。

要匹配子目录,请使用通配符。

*/X/
!C/X/

From the gitignore docs.

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself.

That means X/ will only match a top level X directory.

To match subdirectories, use a wildcard.

*/X/
!C/X/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文