Gitiginore 除了带有 .rst 扩展名的文件之外的所有文件?

发布于 2024-08-16 04:01:49 字数 216 浏览 4 评论 0原文

gitignore 中的 ** 和 * 有点令人困惑。这是我在 .gitignore 中的内容:

*
!*.rst

这适用于根目录中的所有 *.rst 文件。子目录中的 .rst 文件怎么样?

我尝试过

*
!*.rst
!**/*.rst

但这并没有改变任何东西。

The ** and * in gitignore are a bit confusing. Here is what I have in .gitignore:

*
!*.rst

This works for all *.rst files in the root directory. What about .rst files in subdirectories?

I tried

*
!*.rst
!**/*.rst

But this does not change anything.

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

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

发布评论

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

评论(2

笔芯 2024-08-23 04:01:49

在 .gitignore 中尝试以下操作,

*
!*.rst
!*/

这样可以告诉 git 不要忽略子目录。

Try the following in your .gitignore

*
!*.rst
!*/

This way you tell git to not ignore subdirectories.

旧人 2024-08-23 04:01:49

如果您阅读此SO答案,您会意识到Git 忽略文件的方式取决于系统。

gitignore 手册页清楚地表明 glob 将是未更改地传递给系统的 fnmatch 库函数

那么您使用什么操作系统和 Git 发行版(Unix 或 Windows 上的 Msysgit)?
因为在 Windows 上,“**”不能很好地工作(如果有的话)。

另外,请确保在 .gitignore 文件中声明 *.rst 文件之前,它们尚未添加到缓存中。在 .gitignore 按预期工作之前,需要将它们从缓存中删除(并提交清除的缓存)(另请参阅此 博客文章)

If you read this SO answer, you will realize the way Git ignore files is system-dependent.

the gitignore manpage clearly says that the glob will be passed un-altered to the system's fnmatch library function

So what OS and Git distro are you using (Unix, or Msysgit on Windows)?
Because on Windows, the '**' does not work very well (if at all).

Plus, make sure your *.rst files were not already added to the cache before you declared them in the .gitignore file. They would need to be removed from the cache (and the purged cache committed) before .gitignore works as intended (see also this blog post)

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