gpt4 book ai didi

gitignore 所有子目录中的所有文件,除了 xml 文件

转载 作者:行者123 更新时间:2023-12-04 05:01:29 33 4
gpt4 key购买 nike

我有一个类似于这样的目录结构:

root/
.gitignore
subdir/
.gitignore
subsubdir1/
file.xml
image.png
subsubdir2
file.xml
image.jpg

我想忽略来自 subdir 的所有文件除了 XML 文件。
第二个 .gitignore看起来像这样:
*                   # ignore everything in this directory and its subdirectories
!*/ # do not ignore subdirectories
!*.xml # do not ignore xml files
!.gitignore # and of course have this .gitignore file included too

根据 this以及 SO 和其他网站上的各种其他帖子,这应该可以正常工作,但出于某种原因 git status向我显示 subdir 中的所有文件文件夹未跟踪。

我用过 git rm --cached删除之前跟踪过的所有文件 .gitignore添加了,但这仍然没有成功。

你有什么线索,什么会解决这个问题?

PS:
如果重要的话,我在 Windows 上使用 git。

最佳答案

.gitignore 不支持内联注释。评论需要从他们自己的行开始。

您需要删除 !*/这将最终撤消它之前的行。

如果您想忽略 subdir 中的所有内容而不是 subsubdirs 中的所有内容,那么该行应该是:

!/*

如果你想忽略像 subdir/subsubdir2/image.jpg 这样的文件,那么你可以把那行去掉。

空目录(或其中所有文件都被忽略的目录)不会被添加到 git 中。

我认为(并在我的 linux 系统上确认) .gitignore 被自动排除,因此您可以省略最后一行。

这会留在 subdir/.gitignore 中:
*
!*.xml

关于gitignore 所有子目录中的所有文件,除了 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16106497/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com