忽略资源子文件夹最终会忽略所有资源文件夹

Ignore a resources subfolder ends up ignoring all resources folder

我启动了一个新的 maven 项目,并且有一个资源文件夹,里面有一个“脏”文件夹,如下所示:

resources/
     dirty/
          SC/
     SC/

这是一个包含 csv 表的文件夹,我将使用脚本来清理它们。

我想忽略“dirty”文件夹,而不是资源中的其他文件夹,所以我做了一个 .gitignore 如下:

.idea
dirty/

但是,出于某种原因,它完全忽略了资源文件夹。谁能解释一下这是怎么回事?

尝试为 dirty 目录设置完整路径:

/resources/dirty/

开头的/表示.gitignore所在的根目录

另外,我遇​​到了类似的问题,最后我使用了以下方法:

// ignore the contents of Assets directory
Assets/*
// but keep track of the following subdirectories inside Assets:
!Assets/dir_to_keep/
!Assets/other_dir_to_keep/

参考 .gitignore 文档和下面 this link

中的示例

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar

But, for some reason, it ignores the resources folder completely.

首先,检查resource文件夹是否被实际忽略,选择一个不应被忽略的文件:

git check-ignore -v resource/SC/aFile

如果returns什么都没有,那么resource不会被忽略。

正如 OP 评论的那样:

I found that it showed as ignored because there's nothing inside the resources/SC folder.

When I run my cleaner script and the clean tables appeared in resources/SC the foder color changes from ignored (yellow) to unstaged (red).