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

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

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

但是事实并非如此,因此我认为我不应该忽略.idea foler。 但是,我进行了快速搜索,在此处找到了某人的示例.gitignore文件,该文件显然忽略了.idea文件夹。

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


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

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


忽略整个.idea文件夹不一定是最好的主意。这里有许多类似的讨论。

  • 如何在Git源代码管理不断变化的情况下处理IntelliJ IDEA项目文件?
  • Intellij Idea 9/10,要检查(或不检查)源代码管理的文件夹是什么?
  • .idea文件夹是否应保留在源代码控制下?

但我建议您查看有关此问题的官方常见问题解答。


尽管PyCharm的文档建议,我还是建议在共享项目时忽略.idea文件夹。

虽然共享您的项目设置并不是一个天生的坏主意,但是您应该注意一些例外情况和潜在问题。

  • workspace.xml文件包含各种用户特定的设置,例如环境变量,光标位置和Python SDK位置。

    • 环境变量可能包括私人数据,例如用户名和密码
  • dictionaries文件夹包含自定义拼写,如果两个开发人员具有相同的名称,则可能导致冲突。
  • .idea文件夹是特定于PyCharm的,这意味着使用其他IDE的开发人员可能导致项目不同步。
  • IntelliJ自己的文档包括一些不应共享的特定文件的警告。

如果您决定共享.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 .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
  • All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)

Be careful about sharing the following:

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

You may consider not to share the following:

  • .iml files for the Gradle or Maven based projects, since these files will be generated on import
  • gradle.xml file, see this discussion
  • user dictionaries folder (to avoid conflicts if other developer has the same name)
  • XML files under .idea/libraries in case they are generated from Gradle or Maven project

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


.idea /文件夹只是JetBrain存储数据的方式。它位于IntelliJ和PyCharm中,因此,可以忽略。