gitignore does not ignore .idea directory
GitGitignoreGit Problem Overview
Working on a Symfony2 project using phpStorm IDE, I have added couple of files to git ignore but one file despite being added to git ignore is always appearing....I have tried multiple times but its always there
.gitignore file:
/app/config/parameters.yml
/bin/
/build/
/composer.phar
/vendor/
/web/bundles/
/app/bootstrap.php.cache
/app/cache/*
!app/cache/.gitkeep
/app/config/parameters.yml
/app/logs/*
!app/logs/.gitkeep
/app/phpunit.xml
#IDE metadata
**.idea/**
#Bash files
run.sh
And it is the .idea folder/files that git just will not ignore:
On branch develop
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/workspace.xml
no changes added to commit (use "git add" and/or "git commit -a")
Any idea why git will just not ignore the whole directory like i have specyfied in gitignore...?
Git Solutions
Solution 1 - Git
Git never ignores changes to tracked files. As it appears as modified, the file is under version control (the idea/workspace.xml file usually should not be) and thus changes to it are tracked. Delete it from the index, leaving your local copy intact with git rm --cached .idea/workspace.xml
and commit this change. From then on it will be ignored unless you force-add it back to the repository or change your gitignore settings.
Solution 2 - Git
Once you commit the file it will begin to be tracked.
In order to remove the file from this point you have to remove them from the repository.
What you need to do now is to delete the entire .idea
folder, commit the deletion, add the idea
extension to your .gitignore
file.
Note
You can still ignore added files with the assume-unchanged
flag
> --[no-]assume-unchanged
> When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.
>
When the assume unchanged
bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index.
> If you want to change the working tree file, you need to unset the bit to tell Git.
> Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
Explaining how to do from command line, can be done via IDEA as well.
# Remove the file from the repository
git rm --cached .idea/
# now update your gitignore file to ignore this folder
echo '.idea' >> .gitignore
# add the .gitignore file
git add .gitignore
git commit -m "Removed .idea files"
git push origin <branch>
Solution 3 - Git
#idea folder
.idea/
This worked fine for me
Solution 4 - Git
I added this in the gitignore file and worked for me
**/.idea