Git 忽略和 Maven 目标

发布于 2024-07-24 11:10:18 字数 186 浏览 4 评论 0原文

任何人都知道是否可以忽略 git 管理的文件结构中特定目录的所有实例。

我希望排除具有多个子模块的 Maven 项目中的所有“目标”文件夹。 我知道我可以在顶级 .gitignore 中明确排除它们中的每一个,但我真的希望能够指定一个像 **/target/* 这样的模式,让它自动忽略子目录中的实例?

这可能吗?

Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.

I'm looking to exclude all the 'target' folders in a maven project with a number of submodules. I know I can explicitly exclude each of them in a top level .gitignore, but I'd really like to be able to specify a pattern like **/target/* there to have it automatically ignore the instance in sub directories?

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

小女人ら 2024-07-31 11:10:18

根目录中的 .gitignore 文件确实适用于所有子目录。 我的看起来像这样:

.classpath
.project
.settings/
target/

这是在一个多模块 Maven 项目中。 所有子模块均使用 m2eclipse 作为单独的 Eclipse 项目导入。 我没有更多的 .gitignore 文件。 事实上,如果您查看 gitignore 手册页

.gitignore 文件读取模式
在与路径相同的目录中,
在任何父目录中
...

所以这应该适合你。

The .gitignore file in the root directory does apply to all subdirectories. Mine looks like this:

.classpath
.project
.settings/
target/

This is in a multi-module maven project. All the submodules are imported as individual eclipse projects using m2eclipse. I have no further .gitignore files. Indeed, if you look in the gitignore man page:

Patterns read from a .gitignore file
in the same directory as the path, or
in any parent directory

So this should work for you.

四叶草在未来唯美盛开 2024-07-31 11:10:18

可以在 .gitignore 文件中使用模式。 请参阅 gitignore 手册页。 模式 */target/* 应忽略任何名为 target 的目录及其下的任何内容。 或者您可以尝试 */target/** 忽略 target 下的所有内容。

It is possible to use patterns in a .gitignore file. See the gitignore man page. The pattern */target/* should ignore any directory named target and anything under it. Or you may try */target/** to ignore everything under target.

只为守护你 2024-07-31 11:10:18

正如 Abhijeet 的评论中已经指出的那样,您只需添加以下行即可:

/target/**

\.git\info\ 文件夹中的 排除 文件。

然后,如果您想删除远程存储库中的 target 文件夹,您需要首先从本地存储库中手动删除该文件夹,提交然后推送它。 那是因为 git 会首先向您显示修改后的目标文件夹的内容。

As already pointed out in comments by Abhijeet you can just add line like:

/target/**

to exclude file in \.git\info\ folder.

Then if you want to get rid of that target folder in your remote repo you will need to first manually delete this folder from your local repository, commit and then push it. Thats because git will show you content of a target folder as modified at first.

水染的天色ゝ 2024-07-31 11:10:18

在 gitignore 中从所有不需要的文件中添加以下行

/target/
*/target/**
**/META-INF/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

add following lines in gitignore, from all undesirable files

/target/
*/target/**
**/META-INF/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
我也只是我 2024-07-31 11:10:18

我忽略了 git 中目标文件夹中的所有类。
在打开的 .gitignore 文件中添加以下行:

/.class

*/target/**

它非常适合我。 尝试一下。

I ignore all classes residing in target folder from git.
add following line in open .gitignore file:

/.class

OR

*/target/**

It is working perfectly for me. try it.

动听の歌 2024-07-31 11:10:18

对于 Spring Tool Suite,将以下忽略资源添加到 .gitignore 文件中并提交到存储库中

*.classpath
*.class
*.prefs
*.jar
*.lst
*.project
*.factorypath
*.original
target/
.settings/
.apt_generated
.sts4-cache
.springBeans

For the Spring Tool Suite, Add the following ignore resources to .gitignore file and commit into the repository

*.classpath
*.class
*.prefs
*.jar
*.lst
*.project
*.factorypath
*.original
target/
.settings/
.apt_generated
.sts4-cache
.springBeans
时常饿 2024-07-31 11:10:18

对于多模块存储库,除了 @Gleidosn 答案之外,我还会添加以下表达式以考虑嵌套目标文件夹:

**/target/

For multi-module repositories, in addition to @Gleidosn answer I would add the following expression to take into consideration the nested target folders:

**/target/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文