Git 应该跟踪 .idea 文件夹中的哪些文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43198273/
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
Which files in .idea folder should be tracked by Git?
提问by PHPst
Unlike Netbeans, in Jetbrains IDEs, the setting files related to user and team are mixed in the same folder that make it a tricky when you need to push them to git.
与 Netbeans 不同的是,在 Jetbrains IDE 中,与用户和团队相关的设置文件混合在同一个文件夹中,这使得当您需要将它们推送到 git 时会很棘手。
There is a number of sample git ignore files for these IDEs and https://intellij-support.jetbrains.com/hc/articles/206544839page on git site.
这些 IDE 和git 站点上的https://intellij-support.jetbrains.com/hc/articles/206544839页面有许多示例 git ignore 文件。
However after using them for a months we figure out that it is safer and actually more convenient to do the reverse. I mean ignoring all .idea
files and adding only team related settings explicitly. (instead of adding all and ignoring some).
然而,在使用它们一个月后,我们发现相反的做法更安全,实际上更方便。我的意思是忽略所有.idea
文件并仅显式添加与团队相关的设置。(而不是添加所有并忽略一些)。
The main thing that can be shared among developers is code style configs. So using IDE auto-reformatting option all team will follow a consistent style.
开发人员之间可以共享的主要内容是代码样式配置。因此,使用 IDE 自动重新格式化选项,所有团队都将遵循一致的风格。
Beside that, the question is that which other files are recommenced to be included not ignored? Why?
除此之外,问题是重新开始包含哪些其他文件不会被忽略?为什么?
answer: I came up with this: https://github.com/salarmehr/idea-gitignore
回答:我想出了这个:https: //github.com/salarmehr/idea-gitignore
采纳答案by PHPst
After some investigation I came up with the following .idea/.gitignore
file:
经过一番调查,我想出了以下.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
Above files should practically be identical for all team members.
对于所有团队成员,上述文件实际上应该是相同的。
answer: I came up with this: https://github.com/salarmehr/idea-gitignore
回答:我想出了这个:https: //github.com/salarmehr/idea-gitignore
回答by Matt Leidholm
Jetbrains has some official guidanceon which files should notbe checked in, and which files should probably notbe checked in, depending on your usage. According to that page, you should check in all files in the .idea
directory except:
Jetbrains 有一些关于哪些文件不应签入以及哪些文件可能不应签入的官方指南,具体取决于您的使用情况。根据该页面,您应该检入.idea
目录中的所有文件,除了:
workspace.xml
tasks.xml
workspace.xml
tasks.xml
And probably also:
可能还有:
- the xml files in the
dictionary
subdirectory
dictionary
子目录中的xml文件
While the particular answer may depend on your team's particular practices, in my experience, following that guidance generally results in correct separation of user settings and shared project configuration.
虽然特定的答案可能取决于您团队的特定实践,但根据我的经验,遵循该指南通常会正确分离用户设置和共享项目配置。
Some examples of files that shouldbe shared, according to this guidance:
根据本指南,一些应该共享的文件示例:
ant.xml
, which, if you use Ant to build your project, points IDEA to your build files and configures properties that should be used to build.vcs.xml
, which specifies the Version Control configuration for your projectencodings.xml
, which specifies how IDEA should treat the text files in your projectmodules.xml
, which points IDEA to each of your project's module configuration files, which should also be shared in your VCS.- all files under the
runConfigurations
subdirectory, which tells IDEA what it needs to do to run your application codeStyleSettings.xml
, which, as you have alluded to, puts your whole team on the same page in terms of automatic code formatting
ant.xml
,如果您使用 Ant 构建项目,则将 IDEA 指向您的构建文件并配置应该用于构建的属性。vcs.xml
, 指定项目的版本控制配置encodings.xml
,它指定了 IDEA 应该如何处理项目中的文本文件modules.xml
,它将 IDEA 指向您项目的每个模块配置文件,这些文件也应该在您的 VCS 中共享。runConfigurations
子目录下的所有文件,它告诉 IDEA 它需要做什么来运行你的应用程序codeStyleSettings.xml
,正如您所提到的,这使您的整个团队在自动代码格式化方面处于同一页面
Depending on your team's usage, there may be more or less, but those are some of the biggest examples.
根据您团队的使用情况,可能会有更多或更少,但这些是一些最大的例子。
回答by ninj
I prefer not to check in the .idea
folder or .iml
files at all.
我根本不想检查.idea
文件夹或.iml
文件。
- If you want to share editor styles, consider using a
.editorconfig
file, the JetBrains IDEs support these now. - For other things, like build settings you could try to lean on your build tool, e.g. use
maven
orgradle
build files to carry specific setups. - Obviously there's a bunch of other things that won't be covered, but most of them can be solved by well documented conventions.
- 如果您想共享编辑器样式,请考虑使用
.editorconfig
文件,JetBrains IDE 现在支持这些。 - 对于其他事情,例如构建设置,您可以尝试依赖构建工具,例如使用
maven
或gradle
构建文件来进行特定设置。 - 显然还有很多其他的事情不会被涵盖,但其中大部分都可以通过有据可查的约定来解决。
回答by kriegaex
I use both IDEA and Eclipse, but not Netbeans. I nevercommit any project files but make sure that I have a Maven build as the leading tool, then I can easily import the Maven project into any IDE with Maven support and also refresh from Maven once I change it. For Eclipse and IDEA this works beautifully.
我同时使用 IDEA 和 Eclipse,但不使用 Netbeans。我从不提交任何项目文件,但确保我有一个 Maven 构建作为主要工具,然后我可以轻松地将 Maven 项目导入任何具有 Maven 支持的 IDE,并在我更改它后从 Maven 刷新。对于 Eclipse 和 IDEA,这非常有效。
My .gitignorefile looks like this for all of my projects:
我的所有项目的.gitignore文件都是这样的:
# Eclipse
.settings/
.classpath
.project
# IntelliJ IDEA
.idea/
*.iml
# Maven
target/
Plus other, project-specific files or directories.
加上其他特定于项目的文件或目录。
回答by YoannFleuryDev
It's recommended not to commit all the .idea
folder because it's for configurations. Like the *.iml
file.
建议不要提交所有.idea
文件夹,因为它是用于配置的。喜欢这个*.iml
文件。
If I use Netbeans instead of Intellij, I don't want these config files. It is useless and maybe a little dangerous for conflicts.
如果我使用 Netbeans 而不是 Intellij,我不需要这些配置文件。它是无用的,而且可能对冲突有点危险。