限制.gitignore的深度(Limit depth of .gitignore)

编程入门 行业动态 更新时间:2024-10-27 04:36:55
限制.gitignore的深度(Limit depth of .gitignore)

出于各种原因,我在项目根目录下的.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).

最满意答案

你想这样做:

/*.c

我正在寻找一些从引用页面引用,并发现这个确切的例子在那里! 哎呀!

前导斜杠匹配路径名的开头。 例如, "/*.c" "mozilla-sha1/sha1.c" . "/*.c"与"cat-file.c" "/*.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".

更多推荐

本文发布于:2023-07-26 00:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268295.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:深度   gitignore   depth   Limit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!