What to gitignore from the .idea folder?

前端 未结 9 1725
天命终不由人
天命终不由人 2020-11-29 14:37

Possible Duplicate:
Intellij Idea 9/10, what folders to check into (or not check into) source control?

I star

相关标签:
9条回答
  • 2020-11-29 14:51

    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.io


    EDIT Disclaimer: 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

    # 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
    
    0 讨论(0)
  • 2020-11-29 14:57

    in my case /**/.idea/* works well

    0 讨论(0)
  • 2020-11-29 15:02

    For a couple of years I was a supporter of using a specific .gitignore for IntelliJ with this suggested configuration.

    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.

    So my suggestion would be to leave all editor config files out of project and have users configure editor to their liking. Things like code styling can and should be configured at build level; say using Google Code Style or CheckStyle directly on Maven/Gradle/sbt/etc.

    This ensures consistency and leaves editor files out of source code that, in my personal opinion, is where they should be.

    0 讨论(0)
  • 2020-11-29 15:10

    While maintaining the proper .gitignore file is helpful, I found this alternate approach is way cleaner and easier to use.

    • Create dummy folder my_project and inside that git clone my_real_project the actual project repo.
    • Now while opening the project in IDE (Intellij/Pycharm) open the folder my_project and mark my_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.

    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.

    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.

    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

    Hope this helps.

    0 讨论(0)
  • 2020-11-29 15:11
    • Remove .idea folder

      $rm -R .idea/
      
    • Add rule

      $echo ".idea/*" >> .gitignore
      
    • Commit .gitignore file

      $git commit -am "remove .idea"
      
    • Next commit will be ok

    0 讨论(0)
  • 2020-11-29 15:13

    The official support page should answer your question.

    So in your .gitignore you might ignore the files ending with .iws, and the workspace.xml and tasks.xml files.

    0 讨论(0)
提交回复
热议问题