Java Maven 项目中的哪些文件应该提交给 git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51792830/
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
What files in a Maven project should be committed to git?
提问by tyleax
I want to know what files in a Maven project should be committed to git.
我想知道 Maven 项目中的哪些文件应该提交给 git。
Am I suppose to perform a mvn clean
before committing, or do I add certain files to the .gitignore
file?
我是否应该mvn clean
在提交之前执行 a ,或者我是否将某些文件添加到.gitignore
文件中?
采纳答案by Mincong Huang
Personally I use Maven gitignore and Java gitignore for a Maven project. You might need to adjust it with the languages used in your Maven project.
我个人将 Maven gitignore 和 Java gitignore 用于 Maven 项目。您可能需要使用 Maven 项目中使用的语言对其进行调整。
https://github.com/github/gitignore/blob/master/Maven.gitignore
https://github.com/github/gitignore/blob/master/Maven.gitignore
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
https://github.com/github/gitignore/blob/master/Java.gitignore
https://github.com/github/gitignore/blob/master/Java.gitignore
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Is it good practice to perform
mvn clean
before committing, or do I add certain files to the .gitignore file?
mvn clean
在提交之前执行是否是一种好习惯,或者我是否将某些文件添加到 .gitignore 文件中?
Add rules to your .gitignore
file first, which makes Git ignores the undesired files correctly. Understanding Maven standard directory layoutwill also help you better determine which are the undesired directories.
首先将规则添加到您的.gitignore
文件中,这使得 Git 可以正确忽略不需要的文件。了解Maven 标准目录布局也将帮助您更好地确定哪些是不需要的目录。
回答by mc20
Check this:
检查这个:
https://www.gitignore.io/api/maven
https://www.gitignore.io/api/maven
In general you should ignore all targets and metadata. If you ignore targets, mvn clean
is not required before pushing.
通常,您应该忽略所有目标和元数据。如果忽略目标,mvn clean
则不需要推送。
回答by davidxxx
Is it good practice to perform mvn clean before committing, or do I add certain files to the .gitignore file?
在提交之前执行 mvn clean 是一种好习惯,还是将某些文件添加到 .gitignore 文件中?
Executingmvn clean
before committing is not practical at all. Developers can forget that and besides they should rebuild their projects at each commit.
The correct way is using .gitignore
to specify files to ignored in the tracking. Just commit it and push into the remote branch and all developers could work with the same rules.
mvn clean
在提交之前执行根本不切实际。开发人员可以忘记这一点,此外他们应该在每次提交时重建他们的项目。
正确的方法是使用.gitignore
指定要在跟踪中忽略的文件。只需提交并推送到远程分支,所有开发人员都可以使用相同的规则。
I want to know what files in a Maven project should be committed to git.
我想知道 Maven 项目中的哪些文件应该提交给 git。
You want to commit/push files that you want to version/track.
But it is very broad. You cannot have rules just for Maven. Maven have some specificities (target
folder for example that you want to ignore) but you would have probably more things to ignore.
You want to generally commit/push the source code and application configuration files such as pom.xml
or any configuration files used in your build but you can also add any other kind of files. For example committing a changelog or even a word document (more rare but possible) may also be valid.
Generally what you don't want to commit are files that :
您要提交/推送要版本/跟踪的文件。
但它非常广泛。你不能只为 Maven 制定规则。Maven 有一些特殊性(target
例如您想忽略的文件夹),但您可能有更多要忽略的内容。
您通常希望提交/推送源代码和应用程序配置文件,例如pom.xml
构建中使用的任何配置文件,但您也可以添加任何其他类型的文件。例如,提交一个变更日志甚至一个 word 文档(更罕见但可能)也可能是有效的。
通常,您不想提交的文件是:
- depends on the developer machine (IDE, custom files)
- created by a build operation (
target
folder in Maven but you could also have other folders according to your pom configuration) - temporary files using during the build, the application execution or still the release operations.
- archives
- 取决于开发者机器(IDE、自定义文件)
- 由构建操作创建(
target
Maven 中的文件夹,但您也可以根据 pom 配置拥有其他文件夹) - 在构建、应用程序执行或发布操作期间使用的临时文件。
- 档案