如何忽略除一个之外的所有 dist 文件夹?

How to ignore all dist folders except the one?

我们的项目中确实有几个名为 dist 的文件夹。 git 将忽略这些。另一方面,仅将 dist/ 放入 .gitignore 文件在使用 Bower 时确实会产生副作用,因为 bower_components/ 中的 dist 文件夹也会被忽略。

关于如何正确定义规则的任何建议,忽略 dist 个文件夹,bower_components 中的文件夹除外?

当然可以:

dist/
!bower_components/**/dist/