Spring Initializr .gitignore 意图(或理解意图)

Spring Initializr .gitignore intent (or making sense of the intent)

我正在创建一个新的 Spring 启动应用程序。我对 .gitignore 模式非常熟悉,但我看到了一些故意模板化的东西,上面有“意图”的味道。以下是由许多 IDE 中的 Spring Initializr 生成的。

target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
 ...
 ...
build/
!**/src/main/**/build/
!**/src/test/**/build/

我认为这与 maven 的多模块项目功能有关,但 Initializr 应用程序不是多模块(在启动时)。除此之外,我在这里读的是什么? 如果我对我认为正在陈述的内容进行了刺探,那是我不想做的事情(作为一般做法)。

"Ignore target/ folders wherever encountered, but target folders below the top-level in some/path/src/main/deeper/still/target/ include those.

"Oh, do the same for NetBeans build/ directories!"

这不太合理。为什么我要提交构建生成的目标内容?因此,我试图推断 Spring 工程师的意图。

更新

事实上,这正是它的作用,在根目录中包含 targetbuild 目录。 目的是什么?

mkdir -p some/path/src/main/deeper/still/target/
touch !$/test.txt

这个新的 target 目录包含在暂存和提交中。删除它,它就会被忽略。

基本上,这些“包含”(否定排除)确保不会遗漏 src/mainsrc/test 下可能命名为 target 的目录,例如包名在提交中。

根据关于 Spring Initializr gitter 的讨论,Spring 提交者 Andy Wilkinson 指出:

It's to prevent the ignore for Maven's build output directory (target) from causing code in a package named target from being ignored.

在许多情况下,在个别用例中安全删除,“除非你为 Target 工作”(Target Brands, Inc. 可能将包命名为 com.target.api.*)(h/t 给安迪例如)。

我的问题应该在 src/mainsrc/test 的使用中得到回答,但我让 target 这个词的误导弄糊涂了。事实上,我在自己的示例中演示了这一点,但无法通过这个词。哦!