266

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?

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • Tried everything below, added to gitignore, but it still keeps coming back, ignoring gitignore. – Olaf Oct 12 '14 at 10:12
  • Looks like [this same question](http://stackoverflow.com/questions/8156299/why-doesnt-gitignore-work-in-this-case). Check it out and see... – Luca Ballore Feb 19 '16 at 14:30
  • Chek out this link: http://stackoverflow.com/questions/8156299/why-doesnt-gitignore-work-in-this-case. Looks like your same problem. – Luca Ballore Feb 19 '16 at 14:32

14 Answers14

324

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.

Antoine Subit
  • 9,803
  • 4
  • 36
  • 52
amerdidit
  • 3,375
  • 2
  • 13
  • 9
  • The last command should be "mv ../.idea_backup .idea" instead of "git mv ../.idea_backup .idea" to avoid git error – Leo Caseiro May 12 '15 at 06:32
  • 2
    I have to do `git rm .idea` instead of `git add .idea` to do the job – MainActivity Jan 21 '16 at 08:16
  • 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` – jmendiola Apr 13 '16 at 19:58
  • 2
    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 :) – Jonny Asmar Jan 14 '17 at 18:40
  • Thanks! many, many time spent looking for a working solutions and tried severals. This is the simplest way to do that. – edepe Feb 19 '17 at 00:09
  • This works for anything in your .gitignore that is already tracked. – Joe Mar 16 '17 at 12:04
  • Found no solution to this, until reading this, thanks for the solution. Although ensure you have no stashes of the .idea folder as this would require you to delete the stash. – Skelly1983 May 22 '17 at 20:29
  • Months later... I tried this and it worked. I believe this should marked as the answer. – iVoidWarranties Jan 12 '18 at 22:59
  • Thank you! It's very helpful but I would want to change `rm .idea` to `rm -rf .idea`. – Hosang Jeon Jun 09 '18 at 09:28
  • Wow, do people still actually waste their time with this stuff? Something like GitKraken can get this done for you in a second. – Manius Mar 27 '22 at 18:34
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)

chris vdp
  • 2,842
  • 2
  • 22
  • 35
arcanine
  • 1,933
  • 1
  • 15
  • 22
  • 8
    I would also add, only for precision sake, that Idea intellij should be closed when doing this steps. – LoreV Apr 17 '16 at 18:11
36

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
shakram02
  • 10,812
  • 4
  • 22
  • 21
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • 7
    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. – flyingace Feb 01 '15 at 01:49
  • Chek out this link: http://stackoverflow.com/questions/8156299/why-doesnt-gitignore-work-in-this-case. Looks exactly like your same problem. – Luca Ballore Feb 19 '16 at 14:32
  • 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 – Srneczek Oct 03 '16 at 14:10
30

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"
Johnny Willer
  • 3,717
  • 3
  • 27
  • 51
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

howlger
  • 31,050
  • 11
  • 59
  • 99
Melski
  • 309
  • 3
  • 4
  • 2
    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` – Godsmith Dec 16 '14 at 10:01
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/
kerner1000
  • 3,382
  • 1
  • 37
  • 57
5

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.

Toskan
  • 13,911
  • 14
  • 95
  • 185
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

PK Gupta
  • 822
  • 10
  • 20
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.

iDon'tKnoware
  • 111
  • 1
  • 7
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.

Eduard
  • 8,437
  • 10
  • 42
  • 64
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.)

Jonny Blaze
  • 103
  • 2
  • 2
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
Kenziiee Flavius
  • 1,918
  • 4
  • 25
  • 57
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

TheTechRobo the Nerd
  • 1,249
  • 15
  • 28
-1

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

josef
  • 872
  • 9
  • 8