如何使用 gitignore 提及一次以忽略来自不同目录的 2 个同名文件夹?

How to mention once to ignore 2 folders with same name from different directories using gitignore?

我的项目中有以下文件夹。

public/first/A
public/second/A
public/first/B
public/second/B

同样,我还有其他文件夹,它们也在 public/firstpublic/second 中。

要忽略这些文件夹,我需要在 .gitignore 中添加以下内容:

/public/first/A
/public/second/A
....

有没有一种方法可以让我在 gitignore 中仅提及一次 AB 文件夹,它们将被 /public/first/public/second 忽略。

Note: Folders with A & B name with different content might be available in other folders like public/first/app/A and it should not be ignored.

假设没有/public/third/A场景,可以使用通配符指定firstsecond部分。像这样

/public/*/A/
/public/*/B/

此外,您需要在 git 忽略的文件夹后添加一个 /。如果不这样做,git 会将其视为文件声明而不是文件夹。