git '.gitignore' 文件中应该忽略哪些项目文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44657300/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:47:59  来源:igfitidea点击:

What project files are supposed to ignore in '.gitignore' file?

gitmavengithubspring-bootrepository

提问by user252514

I have created my first git repository and trying to put Spring Boot project.

我已经创建了我的第一个 git 存储库并尝试放置 Spring Boot 项目。

In the initial git asked to configure ".gitignore" file but i was not sure what files must (supposed to) be in, so i ignored ?

在最初的 git 要求配置“.gitignore”文件但我不确定哪些文件必须(应该)在,所以我忽略了?

In my first commit-push, i see several files APART FROM pom.xml and some of my .java files like,

在我的第一次提交推送中,我看到几个文件 APART FROM pom.xml 和我的一些 .java 文件,例如,

.classpath
.gitignore
.project
.settings/org.eclipse.core.resources.prefs
.settings/org.eclipse.jdt.core.prefs
.settings/org.eclipse.m2e.core.prefs

And i am not sure why they are here ?
are they supposed to be there ?

我不知道他们为什么在这里?
他们应该在那里吗?

How and where to create .gitignore file ?

如何以及在何处创建 .gitignore 文件?

回答by Michael W?lm

Have a look into https://www.gitignore.io/There you can create your recommended gitignore based on what you are using.

查看https://www.gitignore.io/在那里您可以根据您使用的内容创建推荐的 gitignore。

For Eclipse it says:

对于 Eclipse,它说:

# Created by https://www.gitignore.io/api/eclipse

### Eclipse ###

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core      
.project

# JDT-specific (Eclipse Java Development Tools)     
.classpath

# End of https://www.gitignore.io/api/eclipse

I had many discussions in teams whether to put IDE based files in GIT or not. Some like it, some say every developer knows how to configure their IDE for the project based on the pom.xml.

我在团队中进行了多次讨论,是否将基于 IDE 的文件放在 GIT 中。有人喜欢它,有人说每个开发人员都知道如何根据 pom.xml 为项目配置他们的 IDE。

My opinion now also is, keep away all IDE files from VCS.

我现在的观点也是,远离 VCS 的所有 IDE 文件。

回答by Mark Adelsberger

The .classpathfile, .projectfile, and .settings/directory are used by the Eclipse IDE.

.classpath文件,.project文件和.settings/目录由Eclipse IDE中使用。

There are differing opinions about putting IDE-specific project files under source control. I prefer to exclude them (and let the IDE generate its project files from the pom, provided it has decent Maven integration - which eclipse does) because I've seen sharing them to cause more problems than it solves. Other people will probably tell you they should all be included, and I'll leave it to them to justify their reasons for that; point is, I don't believe there's a single definitive consensus on this.

关于将特定于 IDE 的项目文件置于源代码控制之下,存在不同意见。我更喜欢排除它们(并让 IDE 从 pom 生成它的项目文件,前提是它有不错的 Maven 集成——eclipse 就是这样),因为我已经看到共享它们会导致比它解决的问题更多的问题。其他人可能会告诉你他们都应该被包括在内,我会让他们来证明他们的理由;关键是,我不相信对此有一个明确的共识。

The .gitignorefile contains ignore rules. It specifically contains rules that are meant to be shared through the repository, so it shouldbe included. (If you have ignore rules that you don'tmean to share through the repository, there are other files where those would be defined; see the git ignore docs.)

.gitignore文件包含忽略规则。它特别包含旨在通过存储库共享的规则,因此应该包括在内。(如果您有打算通过存储库共享的忽略规则,则还有其他文件将定义这些规则;请参阅 git ignore 文档。)

回答by JUAN CALVOPINA M

When you use any IDE to develop an application, they usually generate an additional set of files where they save the project settings. It is considered bad practice to upload these settings to a version control tool such as git, svn, etc, because these configurations are specific to the development environment of each developer, in some cases it can prevent the project from opening properly in the IDE, because it tries to look for resources that are not on your PC, for this reason it is advisable not to upload these configurations.

当您使用任何 IDE 开发应用程序时,它们通常会生成一组额外的文件,用于保存项目设置。将这些设置上传到 git、svn 等版本控制工具被认为是不好的做法,因为这些配置特定于每个开发人员的开发环境,在某些情况下会阻止项目在 IDE 中正常打开,因为它会尝试寻找不在您 PC 上的资源,因此建议不要上传这些配置。

How to avoid to upload the IDE's configurations?

如何避免上传IDE的配置?

Gitgives us the .gitignorefile, where we can set all files that we want to ignore. Just create the .gitignorefile in your main project folder, for example ~/workspace/my-project/, open that file with any text editor (even within your IDE) and add the files to be ignored.

Git给我们.gitignore文件,我们可以在其中设置我们想要忽略的所有文件。只需.gitignore在您的主项目文件夹中创建文件,例如~/workspace/my-project/,使用任何文本编辑器(甚至在您的 IDE 中)打开该文件并添加要忽略的文件。

As @Michael says, you can generate a set of files to ignore in base of IDE that you are using, take a look at this link, for example for eclipse (click hereto generate)copy and paste the configuration within your .gitignorefile.

正如@Michael 所说,您可以在您使用的 IDE 基础中生成一组要忽略的文件,请查看此链接,例如对于 eclipse (单击此处生成),将配置复制并粘贴到您的.gitignore文件中。

If you have already uploaded these configurations to your repository, you must delete them so that the new gitignore configuration takes effect, check out these links revert changes in git, remove files from git

如果您已经上传这些配置你的资料库,则必须将其删除,以使新gitignore配置生效,请查看以下链接还原在git的变化从混帐删除文件