Python 将 PyCharm 与 Git 一起使用时,我应该忽略 .idea 文件夹吗?

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

Should I ignore the .idea folder when using PyCharm with Git?

pythongitpycharm

提问by Ray

I read about Git integration in PyCharm, and created a Git repository from PyCharm. I did this in PyCharm because I was hoping PyCharm would know whether the .ideafolder should be ignored, and if that's the case, it would automatically create a .gitignorefile with the line .idea/in it.

我阅读了 PyCharm 中的 Git 集成,并从 PyCharm 创建了一个 Git 存储库。我在 PyCharm 中这样做是因为我希望 PyCharm 知道是否.idea应该忽略该文件夹,如果是这种情况,它会自动创建一个.gitignore包含该行的文件.idea/

But it didn't, so I assumed that I shouldn't ignore the .ideafoler. However, I did a quick search and found someone's example .gitignorefile, here, which clearly ignores the .ideafolder.

但它没有,所以我认为我不应该忽略.ideafoler。但是,我进行了快速搜索,找到了某人的示例.gitignore文件here,该文件显然忽略了该.idea文件夹。

So, my question is, should the .ideafolder be ignored or not?

所以,我的问题是,是否应该.idea忽略该文件夹?

回答by Jake

The .idea/ folder is just the way that JetBrain's stores data. It's in IntelliJ and PyCharm, so, yes, it can be ignored.

.idea/ 文件夹正是 JetBrain 存储数据的方式。它在 IntelliJ 和 PyCharm 中,所以,是的,它可以被忽略。

回答by Artem Zaytsev

All the settings files in the .idea directory should be put under version control except the workspace.xml, which stores your local preferences. The workspace.xml file should be marked as ignored by VCS.

-PyCharm 2017.3 project documentation

.idea 目录中的所有设置文件都应置于版本控制之下,但 workspace.xml 除外,它存储您的本地首选项。Workspace.xml 文件应被VCS 标记为已忽略

- PyCharm 2017.3 项目文档

To explain further, workspace.xmlcontains user-specific workspace preferences. This includes environment variables, recently accessed files, and cursor position.

为了进一步解释,workspace.xml包含用户特定的工作区首选项。这包括环境变量、最近访问的文件和光标位置。

回答by Stevoisiak

I would suggest ignoring the .ideafolder when sharing your project,in spite of what PyCharm's documentationrecommends.

我建议.idea在共享项目时忽略该文件夹,尽管PyCharm 的文档建议这样做。

While sharing your project settings isn't inherentlya bad idea, there are several exceptions and potential issues you should be aware of.

在共享您的项目设置是不是天生一个坏主意,有几个例外,你应该知道的潜在问题。

  • The workspace.xmlfile contains various user-specific settings, such as environment variables, cursor position, and Python SDK location.
    • Environmental variables may include private data, such as usernames and passwords
  • The dictionariesfolder contains custom spellings, which can cause conflicts if two developers have the same name.
  • The .ideafolder is PyCharm specific, meaning developers using a different IDE can lead to project desynchronization.
  • IntelliJ's own documentationincludes several warnings for specific files that shouldn't be shared.
  • workspace.xml文件包含各种特定于用户的设置,例如环境变量、光标位置和 Python SDK 位置。
    • 环境变量可能包括私有数据,例如用户名和密码
  • dictionaries文件夹包含自定义拼写,如果两个开发人员具有相同的名称,则可能会导致冲突。
  • .idea文件夹是 PyCharm 特定的,这意味着使用不同 IDE 的开发人员可能会导致项目不同步。
  • IntelliJ 自己的文档包含一些针对不应共享的特定文件的警告。

If you dodecide to share .idea, IntelliJ's official documentationgives the following advice

如果你决定的份额.idea的IntelliJ的官方文档给出了以下建议

[The .idea] format is used by all the recent IDE versions by default. Here is what you need to share:

  • All the files under .ideadirectory in the project root exceptthe workspace.xmland tasks.xmlfiles which store user specific settings
  • All the .imlmodule files that can be located in different module directories (applies to IntelliJ IDEA)

Be carefulabout sharing the following:

  • Android artifacts that produce a signed build(will contain keystore passwords)
  • In IDEA 13 and earlier dataSources.ids, datasources.xmlcan contain database passwords. IDEA 14 solves this problem.

You may consider not to sharethe following:

  • .imlfiles for the Gradleor Mavenbased projects, since these files will be generated on import
  • gradle.xmlfile, see this discussion
  • user dictionariesfolder (to avoid conflicts if other developer has the same name)
  • XML files under .idea/librariesin case they are generated from Gradle or Mavenproject

Source: JetBrains - How to manage projects under Version Control Systems

[.idea] 格式被所有最近的 IDE 版本默认使用。以下是您需要分享的内容:

  • 项目根目录下.idea目录下的所有文件,除了存储用户特定设置的workspace.xmltasks.xml文件
  • 可以位于不同模块目录中的所有.iml模块文件(适用于 IntelliJ IDEA)

分享以下内容时要小心

  • 生成签名构建的Android 工件(将包含密钥库密码)
  • 在 IDEA 13 和更早版本的dataSources.ids 中datasources.xml可以包含数据库密码。IDEA 14解决了这个问题

您可以考虑不分享以下内容:

  • 基于GradleMaven的项目的.iml文件,因为这些文件将在导入时生成
  • gradle.xml文件,请参阅此讨论
  • 用户字典文件夹(以避免其他开发人员具有相同名称时发生冲突)
  • .idea/libraries下的XML 文件,以防它们是从 Gradle 或 Maven项目生成的

来源:JetBrains - 如何在版本控制系统下管理项目