Valentin Despa
Valentin Despa

Reputation: 42562

Cannot ignore .idea/workspace.xml - keeps popping up

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?

Upvotes: 270

Views: 127261

Answers (14)

josef
josef

Reputation: 972

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.

Upvotes: 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

Upvotes: 0

Kenziiee Flavius
Kenziiee Flavius

Reputation: 1949

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

Upvotes: 0

Jonny Blaze
Jonny Blaze

Reputation: 103

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

Upvotes: 0

Johnny Willer
Johnny Willer

Reputation: 3917

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"

Upvotes: 32

iDon&#39;tKnoware
iDon&#39;tKnoware

Reputation: 151

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.

Upvotes: 1

Eduard
Eduard

Reputation: 9165

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.

Upvotes: 0

PK Gupta
PK Gupta

Reputation: 822

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

Upvotes: 1

Valentin Despa
Valentin Despa

Reputation: 42562

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

Upvotes: 38

amerdidit
amerdidit

Reputation: 3445

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.

Upvotes: 331

kerner1000
kerner1000

Reputation: 3546

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/

Upvotes: 8

Melski
Melski

Reputation: 309

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

Upvotes: 29

Toskan
Toskan

Reputation: 14931

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.

Upvotes: 7

arcanine
arcanine

Reputation: 1953

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)

Upvotes: 94

Related Questions