ChatGPT解决这个技术问题 Extra ChatGPT

What to gitignore from the .idea folder?

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

What is the recommended .gitignore pattern for 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.

I think, that put IDE files into versioning system is bad idea. Your project will be more tied to particular IDE and you can bring problems for users of other IDEs. I had a few projects with IDE files in VCS and I faced complications. Now I have in VCS just maven files and IDEA generate project files and everything is fine.
@chalimartines I prefer to have everything required for build in the repository. As we don't use Maven and also use a single IDE, it would be a complication NOT to have .idea files in VCS.

B
BuZZ-dEE

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.


The doc recommends "share all the .iml module files", so a .gitignore with the following two lines should be fine: .idea/workspace.xml .idea/tasks.xml
The correct syntax seems to be */.idea/workspace.xml */.idea/tasks.xml
A better syntax is **/.idea/workspace.xml **/.idea/tasks.xml
why is the **/ better than */?
@Vanquish46 : More specifically, the ** recurses through all the sub-folders, so files that meet the criteria are ignored in sub-folders as well.
G
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.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

"By default they suggest you ignore everything from .idea/" - not any more. Currently generated .gitignore doesn't have the .idea/ entry.
Why would you ignore .idea/dictionaries outright?
@Rhymoid I don't know why specifically since I am not the one proposing the .gitignore. I am just showing the tool that does it. My guess is that it is a personal file. You can add stuff in your dictionary that might not be valid for others. Specially when you are cleaning up LINT messages. I believe that if you agree amongst your teammates you might add it to your git repo.
I intended to use the generic 'you', sorry. But with the parallels it has to linting, it totally makes sense to have them in a source repo, because the entries will in fact apply to everyone: the dictionaries are specific to the content of the project! For instance, when working on a parser for C, everyone will run into the problem that the word "punctuator" is falsely marked as a misspelling... unless you share the dictionary.
@user824425 IntelliJ says to be careful about the user dictionaries folder (to avoid conflicts if other developer has the same name) - see intellij-support.jetbrains.com/hc/en-us/articles/…
F
Frankie

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.


That's exactly my point, We should not hassle around .gitignore just for JB as I have explained in my answer.
u
user229044

https://www.gitignore.io/api/jetbrains

Created by 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 

OK! if you want to ingore something, you can go to [gitignore.io/](https://www.gitignore.io ) , it can be very helpful for you to easily find what you wanna!
This is helpful but it would better if you just linked to the file - there are already differences in the online version.
Why not just do .idea/*? Saves a lot of lines.
@Hackinet that's depends on your situation, ignore all files with the * symbol or just only needs ignore some specials files.
C
Cereal

Github uses the following .gitignore for their programs

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

c
craigcaulfield

You can simply ignore all of them by adding .idea/* to the .gitignore file.


s
sasquad92

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


L
Lucio

As stated in the support page, starting with version 2019.1, IntelliJ is capable of adding everything that needs sharing to Version Control automatically.

This is great since the IDE will add just the necessary files to Git in two steps:

Open the project with IntelliJ and wait a moment until the following pop to shows up in the bottom-right corner Select "Always Add"

https://i.stack.imgur.com/nqmSF.png

Alternatively you can select "View Files" and then add them manually.


n
nehem

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.


This answer is completely misleading. /.idea in .gitignore works fine; Usually the problem will be solved after by this command: git rm --cached -r .idea
/.idea doesn't work, You can check other answers and the official guidelines from JB too
I don't understand why you think you need to keep your .gitignore clean. But you can always just put this in your user git config rather than going through this extra dummy folder approach.
Yes, but if you want to ignore all of the .idea files you only need to add /.idea/ to your .gitignore file once and forget about it. Or you can do the same thing in your user .gitconfig and not bother with this dummy folder approach.
No idea why this one got downvoted. I totally agree that IDE stuff must never be .gitignore-d and committed to the repository just because someone thinks this is the only IDE in use for this particular project. What if someone prefers Eclipse? .gitignore should only contain files that can be generated during the build, not ones that cover someone else's preferences for IDE. To all of the downvoters, learn what .git/info/exclude and core.excludesfile are.
P
Pang

Remove .idea folder $rm -R .idea/

Add rule $echo ".idea/*" >> .gitignore

Commit .gitignore file $git commit -am "remove .idea"

Next commit will be ok


ignoring the idea folder is fine as not everyone uses them, and they are not part of your code - you (hopefully) don't need them on production, for instance.
ignoring is fine, but removing is less of a good idea. It contains information for your local workspace.
I'm surprised this is down-voted. Seams to be the best answer here!
The answer is downvoted because it doesn't answer the question. You also don't have to remove your .idea folder in order to gitignore it.
@ChristopherBarber you need to remove it from git origin though