git 从 .idea 文件夹中 gitignore 什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11968531/
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 to gitignore from the .idea folder?
提问by Borek Bernard
Possible Duplicate:
Intellij Idea 9/10, what folders to check into (or not check into) source control?
I started using WebStorm for web development and am not sure what to add and what to exclude from our Git repository. Clearly some files inside the .idea
folder are meant to be version controlled like the external library settings (jsLibraryMappings.xml
) but others will probably change very often and are developer-specific (e.g., workspace.xml
).
我开始使用 WebStorm 进行 Web 开发,但不确定要添加什么以及从 Git 存储库中排除什么。显然,文件.idea
夹中的某些文件应该像外部库设置 ( jsLibraryMappings.xml
)一样受版本控制,但其他文件可能会经常更改并且是特定于开发人员的 (例如,workspace.xml
)。
What is the recommended .gitignore
pattern for WebStorm / IntelliJ IDEA?
.gitignore
WebStorm / IntelliJ IDEA的推荐模式是什么?
P.S. There are already questions about this but usually focus only on whether to include the whole .idea
folder or whether to fully exclude it. I think some of the files inside the .idea
folder should be version controlled while others shouldn't and I'm trying to find out which ones.
PS 已经有关于此的问题,但通常只关注是否包含整个.idea
文件夹或是否完全排除它。我认为文件.idea
夹中的某些文件应该受版本控制,而另一些则不应该,我正在尝试找出哪些文件。
采纳答案by hifkanotiks
The official support pageshould answer your question.
官方支持页面应该可以回答您的问题。
So in your .gitignore
you might ignore the files ending with .iws
, and the workspace.xml
and tasks.xml
files.
因此,在您.gitignore
的文件中.iws
,您可能会忽略以, 和workspace.xml
和tasks.xml
文件结尾的文件。
回答by GabrielOshiro
I just want to present a more recent alternative. There is an online tool that generates .gitignore
files based on operating systems, IDEs and programming languages that you might be using.
我只想提出一个更新的替代方案。有一个在线工具可以.gitignore
根据您可能使用的操作系统、IDE 和编程语言生成文件。
EDITDisclaimer: Do not copy this file, copy the file generated by the website instead, they do a good job on keeping it updated. This is just an example.
编辑免责声明:不要复制此文件,而是复制网站生成的文件,他们在保持更新方面做得很好。这只是一个例子。
The file generated for IntelliJ
contains the following
生成的文件IntelliJ
包含以下内容
# Created by https://www.gitignore.io/api/intellij
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
回答by xgqfrms
https://www.gitignore.io/api/jetbrains
https://www.gitignore.io/api/jetbrains
Created by https://www.gitignore.io/api/jetbrains
由https://www.gitignore.io/api/jetbrains创建
### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
回答by Frankie
For a couple of years I was a supporter of using a specific .gitignore
for IntelliJ with this suggested configuration.
几年来,我一直支持使用特定.gitignore
于 IntelliJ 的建议配置。
Not anymore.
不再。
IntelliJ is updated quite frequently, internal config file specs change more often than I would like and JetBrains flagship excels at auto-configuring itself based on maven/gradle/etc build files.
IntelliJ 更新非常频繁,内部配置文件规范的变化比我想要的要频繁,JetBrains 旗舰在基于 maven/gradle/etc 构建文件自动配置自身方面表现出色。
So my suggestion would be to leave all editor config files out of projectand have users configure editor to their liking. Things like code styling can and should be configured at build level; say using Google Code Styleor CheckStyledirectly on Maven/Gradle/sbt/etc.
所以我的建议是将所有编辑器配置文件都放在项目之外,让用户根据自己的喜好配置编辑器。代码样式之类的东西可以而且应该在构建级别进行配置;比如说直接在 Maven/Gradle/sbt/etc 上使用Google Code Style或CheckStyle。
This ensures consistency and leaves editor files out of source code that, in my personal opinion, is where they should be.
这确保了一致性并将编辑器文件排除在源代码之外,在我个人看来,源代码是它们应该存在的地方。
回答by Cereal
Jetbrains provides the following .gitignore for their programs
Jetbrains 为其程序提供以下 .gitignore
https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
回答by DinoPi
You can simply ignore all of them by adding .idea/*
to the .gitignore
file.
您可以通过添加.idea/*
到.gitignore
文件中来简单地忽略所有这些。
回答by nehem
While maintaining the proper .gitignore
file is helpful, I found this alternate approach is way cleaner and easier to use.
虽然维护正确的.gitignore
文件很有帮助,但我发现这种替代方法更简洁、更易于使用。
- Create dummy folder
my_project
and inside thatgit clone my_real_project
the actual project repo. - Now while opening the project in IDE (Intellij/Pycharm) open the folder
my_project
and markmy_project/my_real_project
as the VCS root. - You can see
my_project/.idea
wouldn't pollute your git repo because it happily lives outside the git repo which is what you want. This way your.gitignore
files stays clean as well.
- 创建虚拟文件夹
my_project
并在其中创建git clone my_real_project
实际项目存储库。 - 现在在 IDE (Intellij/Pycharm) 中打开项目时打开文件夹
my_project
并标记my_project/my_real_project
为 VCS 根。 - 你可以看到
my_project/.idea
不会污染你的 git repo,因为它快乐地生活在你想要的 git repo 之外。这样您的.gitignore
文件也能保持干净。
This approach works better due to the below reasons.
由于以下原因,这种方法效果更好。
1 - .gitignore
file stays clean and we don't have to insert lines related to JetBrains products, that file is better used for binaries and libraries and autogen contents.
1 -.gitignore
文件保持干净,我们不必插入与 JetBrains 产品相关的行,该文件更适合用于二进制文件和库以及自动生成内容。
2 - Intellij keeps updating their projects and the files inside .idea
keep changing every significant release from JB. What this means is we have to keep updating our .gitignore
accordingly which is not an ideal use of time.
2 - Intellij 不断更新他们的项目,其中的文件.idea
不断更改 JB 的每个重要版本。这意味着我们必须相应地不断更新我们的信息.gitignore
,这不是理想的时间利用方式。
3 - Intellij has the flawed pattern here, most editors Atom, VS Code, Eclipse... nobody stores their IDE contents right inside project root. JB shouldn't be an exception either. It's the onus of Jetbrains to keep those files tracked outside project root. They have to refrain from polluting VCS root. This approach does just that. The .idea
folder is kept outside the PROJECT_ROOT
3 - Intellij 在这里有缺陷的模式,大多数编辑器 Atom、VS Code、Eclipse ......没有人将他们的 IDE 内容存储在项目根目录中。JB也不应该例外。Jetbrains 有责任在项目根目录之外跟踪这些文件。他们必须避免污染 VCS 根。这种方法就是这样做的。该.idea
文件夹保存在PROJECT_ROOT
Hope this helps.
希望这可以帮助。
回答by Tai LE
Remove .idea folder
$rm -R .idea/
Add rule
$echo ".idea/*" >> .gitignore
Commit .gitignore file
$git commit -am "remove .idea"
Next commit will be ok
删除 .idea 文件夹
$rm -R .idea/
添加规则
$echo ".idea/*" >> .gitignore
提交 .gitignore 文件
$git commit -am "remove .idea"
下一次提交没问题