Git应该跟踪.idea文件夹中的哪些文件?

时间:2017-04-04 04:29:34

标签: git intellij-idea phpstorm ignore

与Netbeans不同,在Jetbrains IDE中,与用户和团队相关的设置文件混合在同一个文件夹中,当你需要将它们推送到git时,它会变得棘手。

这些IDE有许多示例git ignore文件,git网站上有https://intellij-support.jetbrains.com/hc/articles/206544839页面。

然而,在使用它们几个月之后,我们发现它更安全,实际上更方便。我的意思是忽略所有.idea个文件并明确添加仅与团队相关的设置。 (而不是添加所有并忽略一些)。

开发人员可以共享的主要内容是代码风格配置。因此,使用IDE自动重新格式化选项,所有团队都将遵循一致的风格。

除此之外,问题是重新开始包含哪些其他文件而不被忽略?为什么呢?

回答:我想出了这个:https://github.com/salarmehr/idea-gitignore

5 个答案:

答案 0 :(得分:19)

Jetbrains有some official guidance个文件不应该签入,以及应该哪些文件可能不会被签入,具体取决于您的使用情况。根据该页面,您应该检查.idea目录中的所有文件,除了:

  • workspace.xml
  • tasks.xml

也可能还有:

  • dictionary子目录
  • 中的xml文件

虽然具体答案可能取决于您团队的特定实践,但根据我的经验,遵循该指南通常会导致用户设置和共享项目配置的正确分离。

根据此指南共享的文件的一些示例:

  • ant.xml,如果您使用Ant构建项目,请将IDEA指向构建文件并配置应该用于构建的属性。
  • vcs.xml,指定项目的版本控制配置
  • encodings.xml,指定IDEA应如何处理项目中的文本文件
  • modules.xml,它将IDEA指向您项目的每个模块配置文件,这些文件也应该在您的VCS中共享。
  • runConfigurations子目录下的所有文件,告诉IDEA运行应用程序需要做什么
  • codeStyleSettings.xml,正如您所提到的那样,将您的整个团队放在同一页面上进行自动代码格式化

根据您团队的使用情况,可能会有更多或更少,但这些是一些最大的例子。

答案 1 :(得分:6)

经过一番调查后,我想出了以下.idea/.gitignore文件:

# ignore all .idea files ...
*
# except  ...

# Version Control configuration
!vcs.xml

# how IDEA should treat the text files
!encodings.xml

# automatic code formatting
!codeStyleSettings.xml

# project specific words
!dictionaries

!copyrights
!misc.xml
!sqldialects.xml

对于所有团队成员,上述文件实际上应该是相同的。

回答:我想出了这个:https://github.com/salarmehr/idea-gitignore

答案 2 :(得分:2)

建议不要提交所有.idea文件夹,因为它适用于配置。与*.iml文件一样。

如果我使用Netbeans而不是Intellij,我不想要这些配置文件。这对于冲突来说是无用的,也许有点危险。

答案 3 :(得分:2)

我不想检查2017-04-13 23:20:47 [main] INFO n.myapp.MyApp- Starting MyAppon PC with PID 12292 (F:\test\apps\target\classes started by User in F:\test\apps) 2017-04-13 23:20:47 [main] INFO n.myapp.MyApp- No active profile set, falling back to default profiles: default 2017-04-13 23:20:47 [main] INFO o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4bff7da0: startup date [Thu Apr 13 23:20:47 BST 2017]; root of context hierarchy 2017-04-13 23:20:47 [background-preinit] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.3.4.Final 2017-04-13 23:20:48 [main] INFO o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 8080 (http) 2017-04-13 23:20:48 [main] INFO o.a.catalina.core.StandardService - Starting service Tomcat 2017-04-13 23:20:48 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.5.11 2017-04-13 23:20:48 [Tomcat-startStop-1] ERROR o.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ... 6 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5099) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.authenticator.NonLoginAuthenticator[]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:170) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 8 common frames omitted Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1137) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 common frames omitted 2017-04-13 23:20:48 [main] ERROR o.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:343) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:84) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:548) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) at net.myapp.MyApp.main(MyApp.java:46) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 common frames omitted 2017-04-13 23:20:48 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat 2017-04-13 23:20:48 [main] ERROR o.s.boot.SpringApplication - Application startup failed org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) at net.myapp.MyApp.main(MyApp.java:46) Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:123) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:84) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:548) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ... 8 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:343) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ... 13 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 15 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 17 common frames omitted Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 19 common frames omitted 文件夹或 @SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyApp{ public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } 文件。

  • 如果您想共享编辑器样式,请考虑使用.editorconfig文件,JetBrains IDE现在支持这些。
  • 对于其他内容,例如构建设置,您可以尝试依靠构建工具,例如:使用.idea.iml构建文件来进行特定设置。
  • 显然还有许多其他内容无法涵盖,但大多数内容都可以通过详细记录的惯例来解决。

答案 4 :(得分:1)

我同时使用IDEA和Eclipse,但不使用Netbeans。我从不提交任何项目文件,但确保我有一个Maven构建作为主要工具,然后我可以轻松地将Maven项目导入任何支持Maven的IDE中,并且一旦我更改它就从Maven刷新。对于Eclipse和IDEA来说,这非常有效。

我的 .gitignore 文件对于我的所有项目都是这样的:

# Eclipse
.settings/
.classpath
.project

# IntelliJ IDEA
.idea/
*.iml

# Maven
target/

加上其他项目特定的文件或目录。