Cannot ignore .idea/workspace.xml - keeps popping up
GitIntellij IdeaPhpstormGit Problem Overview
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?
Git Solutions
Solution 1 - Git
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.
Solution 2 - Git
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
)
Solution 3 - Git
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
Solution 4 - Git
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
Solution 5 - Git
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"
Solution 6 - Git
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/
Solution 7 - Git
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.
Solution 8 - Git
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
Solution 9 - Git
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.
Solution 10 - Git
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.
Solution 11 - Git
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.)
Solution 12 - Git
Ignore the files ending with .iws
, and the workspace.xml
and tasks.xml
files in your .gitignore
Reference