限制.gitignore的深度

发布于 2024-09-16 07:33:25 字数 344 浏览 3 评论 0原文

由于各种原因,我在项目根目录的 .gitignore 中添加了以下条目:

 *.c

如我所愿,这会忽略包含的所有 C 文件。但是,我真的只希望根目录中的 C 文件被忽略,而不是所有子目录:

 foo.c
 bar.c
 folder/baz.c

在上面的方案中,我只希望忽略 foo.c 和 bar.c 。我不希望这个 gitignore 规则递归地工作。我该怎么做?

我知道可以使用 !*.c 否定该规则,但我不想对每个子目录都这样做。 (这就是我目前正在做的事情)。

For various reasons, I have the entry in my .gitignore in the root of a project:

 *.c

As I desire, this ignores all C files from being included. However, I really only want the C files to only be ignored in the root directory, and not all the sub-directories:

 foo.c
 bar.c
 folder/baz.c

In the above scheme, I only want foo.c and bar.c ignored. I do not want this gitignore rule to work recursively. How do I do this?

I'm aware of being able to negate the rule with !*.c, but I'd rather not do that for every subdirectory. (This is what I am currently doing).

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

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

发布评论

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

评论(1

糖果控 2024-09-23 07:33:25

您想要这样做:

/*.c

我正在从联机帮助页中寻找一些内容来引用,并发现这个确切的示例就在那里!哎呀!

前导斜杠与路径名的开头匹配。例如,"/*.c" 匹配 "cat-file.c",但不匹配 "mozilla-sha1/sha1.c"

You want to do this:

/*.c

I was looking for a bit from the manpage to quote, and found that this exact example's in there! Oops!

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

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