无法将目标文件夹添加到 .gitignore

use*_*181 1 java git spring bitbucket

我在Bitbucket上有 Spring 模块项目,其中包含 2 个 Spring Boot 应用程序。在根模块中,我有.gitignore文件,在每个应用程序中,我都有.gitignore文件,其中包含以下内容:

config.properties
.classpath
.project
.settings/
.idea/
target/
*.iml
Run Code Online (Sandbox Code Playgroud)

我再次尝试拉项目,但没有任何变化。Config.properties 会被忽略,但目标文件夹不会。每次我进行一些更改时,我都会在 git 更改列表中获得目标文件夹文件。

git 中的目标文件夹文件

小智 5

我想到了几种可能性。

  1. 确保您尚未提交target/文件夹。这将阻止 gitignore 执行其工作并忽略添加的文件夹。

  2. 另一个想法是您有一个多模块项目。确保您正在调用正确的target/文件夹来忽略:How to .gitignore files recursively


小智 5

gitignore 中的新模式适用于现有目录。\n请确保删除 git 中目标文件夹的现有条目:

\n\n
git rm -r --cached etplans-web/target\n
Run Code Online (Sandbox Code Playgroud)\n