Git 忽略和 Maven 目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/991801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Ignores and Maven targets
提问by sgargan
Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.
任何人都知道是否可以忽略由 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?
我希望在具有多个子模块的 maven 项目中排除所有“目标”文件夹。我知道我可以在顶级 .gitignore 中明确排除它们中的每一个,但我真的希望能够在那里指定像 **/target/* 这样的模式让它自动忽略子目录中的实例?
Is this possible?
这可能吗?
采纳答案by baudtack
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.
可以在.gitignore
文件中使用模式。请参阅gitignore 手册页。该模式*/target/*
应忽略任何名为 target 的目录及其下的任何内容。或者您可以尝试*/target/**
忽略目标下的所有内容。
回答by Dominic Mitchell
The .gitignore
file in the root directory doesapply to all subdirectories. Mine looks like this:
.gitignore
根目录中的文件确实适用于所有子目录。我的看起来像这样:
.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:
这是在一个多模块 Maven 项目中。所有子模块都使用 m2eclipse 作为单独的 eclipse 项目导入。我没有更多的.gitignore
文件。实际上,如果您查看gitignore 手册页:
Patterns read from a
.gitignore
file in the same directory as the path, or in any parent directory…
模式从
.gitignore
与路径相同的目录或任何父目录中的文件中读取......
So this should work for you.
所以这应该适合你。
回答by Tomasz Mularczyk
As already pointed out in comments by Abhijeet you can just add line like:
正如 Abhijeet 在评论中已经指出的那样,您可以添加如下行:
/target/**
to excludefile in \.git\info\
folder.
要排除的文件\.git\info\
夹中。
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.
然后,如果您想target
删除远程存储库中的该文件夹,您需要先从本地存储库中手动删除该文件夹,提交然后推送它。那是因为 git 会首先显示修改后的目标文件夹的内容。
回答by Rajeev Rathor
I ignore all classes residing in target folder from git. add following line in open .gitignore file:
我忽略了 git 中驻留在目标文件夹中的所有类。在打开的 .gitignore 文件中添加以下行:
/.class
/.class
OR
或者
*/target/**
*/目标/**
It is working perfectly for me. try it.
它非常适合我。尝试一下。
回答by Gleidosn
add following lines in gitignore, from all undesirable files
在 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/