270

Using PHPStorm, I am trying to ignore the workspace.xml which pops up every-time I try to make a git commit.

My .gitignore looks like:

/.idea/ .idea/workspace.xml 

Because at a point the file was committed, I've also executed:

git rm --cached .idea/workspace.xml and then committed the removal, pushed to a bare repo.

But the file keeps popping up later when I do changes in the project.

Any ideas on what I am missing?

3
  • Tried everything below, added to gitignore, but it still keeps coming back, ignoring gitignore. Commented Oct 12, 2014 at 10:12
  • Looks like this same question. Check it out and see... Commented Feb 19, 2016 at 14:30
  • Chek out this link: stackoverflow.com/questions/8156299/…. Looks like your same problem. Commented Feb 19, 2016 at 14:32

14 Answers 14

331

I was facing the same issue, and it drove me up the wall. The issue ended up to be that the .idea folder was ALREADY commited into the repo previously, and so they were being tracked by git regardless of whether you ignored them or not. I would recommend the following, after closing RubyMine/IntelliJ or whatever IDE you are using:

mv .idea ../.idea_backup rm .idea # in case you forgot to close your IDE git rm -r .idea git commit -m "Remove .idea from repo" mv ../.idea_backup .idea 

After than make sure to ignore .idea in your .gitignore

Although it is sufficient to ignore it in the repository's .gitignore, I would suggest that you ignore your IDE's dotfiles globally.

Otherwise you will have to add it to every .gitgnore for every project you work on. Also, if you collaborate with other people, then its best practice not to pollute the project's .gitignore with private configuation that are not specific to the source-code of the project.

Sign up to request clarification or add additional context in comments.

10 Comments

The last command should be "mv ../.idea_backup .idea" instead of "git mv ../.idea_backup .idea" to avoid git error
I have to do git rm .idea instead of git add .idea to do the job
I also changed add for rm but in my case I had to add -r as well to recursively remove all. git rm -r .idea
Wow... thank you!! Tried this a million different ways to no avail. THIS is the correct step by step approach. The key difference that I was missing was to make sure my IDE was closed - don't miss that step! Excellent answer :)
Thanks! many, many time spent looking for a working solutions and tried severals. This is the simplest way to do that.
|
94

I had this problem just now, I had to do git rm -f .idea/workspace.xml now it seems to be gone (I also had to put it into .gitignore)

1 Comment

I would also add, only for precision sake, that Idea intellij should be closed when doing this steps.
38

I had to:

  • remove the file from git
  • push the commit to all remotes
  • make sure all other committers updated from remote

Commands

git rm -f .idea/workspace.xml git remote | xargs -L1 git push --all 

Other committers should run

git pull 

3 Comments

While I'm glad for this answer, I can't help but feel that it would be more useful if the instructions of how to accomplish the steps (eg, command line directives) were included.
Chek out this link: stackoverflow.com/questions/8156299/…. Looks exactly like your same problem.
shut down IDE \n git rm -f .idea/workspace.xml \n git commit -m "removing workspace.xml" \n edit .gitignore to exclude workspace.xml \n open IDE
33

To remove .idea/ completely from the git without affecting your IDE config you could just do:

git rm -r --cached '.idea/' echo .idea >> .gitignore git commit -am "removed .idea/ directory" 

Comments

29

In the same dir where you see the file appear do:

  • rm .idea/workspace.xml
  • git rm -f .idea/workspace.xml (as suggested by chris vdp)
  • vi .gitignore
  • i (to edit), add .idea/workspace.xml in one of the lines, Esc, :wq

You should be good now

1 Comment

Or, to add the row to .gitignore, just type echo .idea/workspace.xml>>.gitignore. You don't need to open vi for everything. Alternatively, and what would I would do, is to have a separate .gitignore file in the .idea directory: echo workspace.xml>>.idea/.gitignore
8

If you have multiple projects in your git repo, .idea/workspace.xml will not match to any files.

Instead, do the following:

$ git rm -f **/.idea/workspace.xml

And make your .gitignore look something like this:

# 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 ## File-based project format: *.iws # IntelliJ /out/ 

Comments

7

Just tell git to not assume it is changed never matter what:

git update-index --assume-unchanged src/file/to/ignore 

yes, you can remove the files from the git repository. But if your team all use the same IDE or you are by yourself, you probably don't want to do that. For yourself, you want to have an ok starting point to resume working, for your teammates as well.

1 Comment

My issue is that I agree that IDE project metadata files should be saved in git (at least in a commercial setting where you expect most team members to use the same IDE), and that works fine as long as the project files are relatively stable. Recently Android Studio started putting git change logs in the workspace.xml file - which is super annoying. Using --assume-unchanged appears to fix the problem for me, at least as long as I don't want to actually make important updates to the project files.
1

The way i did in Android Studio which is also based on IntelliJ was like this. In commit dialog, I reverted the change for workspace.xml, then it was moved to unversioned file. After that I deleted this from commit dialog. Now it won't appear in the changelist. Note that my gitignore was already including .idea/workspace.xml

Comments

1

Same problem for me with PHPStorm

Finally I solved doing the following:

  • Remove .idea/ directory
  • Move .gitignore to the same level will be the new generated .idea/
  • Write the files you need to be ignored, and .idea/ too. To be sure it will be ignored I put the following:

    • .idea/
    • .idea
    • .idea/*

I don't know why works this way, maybe .gitignore need to be at the same level of .idea to can be ignored this directory.

Comments

0

Since in my case I was performing a first commit of a project, simply deleting .git and .idea folders and then reinitializing git using git init helped to solve a problem. Now I don't have .idea at all.

Comments

0

Unintuitive but so easy to fix once I figured it out: I added the file to .gitignore, then reverted that file in the Commit tab's changelist. It no longer appeared.

(I'm guessing that once the change is automatically added to git by IntelliJ, it no longer will compare against .gitignore. Once reverted, IntelliJ will start comparing against .gitignore before adding the file.)

Comments

0

Just thought i'd share my experience with this.

I had the same issue no matter what I tried but turns the repo I was working on generated a .idea on the top level as you'd expect, but the .gitignore was placed within a folder lower down the directory tree.

So:

.idea // On the level above the .gitignore file application/ - .gitignore // too low to include .idea - otherfile.js 

So my solution was that I needed to create a .gitignore file at the top level of the repo, I was then able to delete / the .idea folder as expected, like so:

.gitignore // Now this can successfully target .idea below .idea application/ - .gitignore - otherfile.js 

Comments

0
mv .idea ../.idea_backup rm .idea # in case you forgot to close your IDE git rm -r .idea git commit -m "Remove .idea from repo" mv ../.idea_backup .idea 

try this

Comments

0

Ignore the files ending with .iws, and the workspace.xml and tasks.xml files in your .gitignore Reference

Update on Oct 17, 2024:

The original reference page has been updated a month ago.

Today, you should ignore .idea/workspace.xml, .idea/usage.statics.xml, and .idea/shelf/. You can put those in the top-level .gitignore file, or the .idea/.gitignore file. As other answers mentioned, you'll need to also run git rm <file> to remove them from the git. The reference page also discussed about other files under .idea/ directory.

In my case, the IDE generated a top-level .gitignore file at the first run. After re-opening the IDE, it generated a .idea/.gitignore file too. Then I only needed to run the command line git rm .idea/workspace.xml to remove it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.