153

I have a Webstorm project that I was about to commit, but before pressing the commit button in the Git Windows GUI, I remembered that I don't want to commit my .idea folder content.

So I used the website that auto generates .gitignores for certain IDEs and added it to my .gitignore file.

All .idea files that are explicitly ignored are still showing up to commit, despite me removing and re-added the files in question.

I've also committed the gitignore file without any other files, and re-pasted my content, but it still is not ignoring the .idea files.

How do I tell Git to refresh or clear its cache?
I tried /cd ing into the directory in question, and typing

git clean -n

but no files show up.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
jozenbasin
  • 2,142
  • 2
  • 14
  • 22

6 Answers6

238

All .idea files that are explicitly ignored are still showing up to commit

you have to remove them from the staging area

git rm --cached .idea

now you have to commit those changes and they will be ignored from this point on.
Once git start to track changes it will not "stop" tracking them even if they were added to the .gitignore file later on.

You must explicitly remove them and then commit your removal manually in order to fully ignore them.


enter image description here

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
182

When you think your git is messed up, you can use this command to do everything up-to-date.

git rm -r --cached .
git add .
git commit -am 'git cache cleared'
git push

Also to revert back last commit use this :

git reset HEAD^ --hard
Kamal Kumar
  • 3,393
  • 2
  • 19
  • 15
  • 9
    Do not use git push if you do not want to push changes to the remote. However if you did, go to version control tab at the bottom of android studio, right click previous commit and choose "Reset current branch to here" – Swapnil Kadam May 29 '18 at 07:56
  • the reset part was at best confusing. but I did up to 'git push', and was fine. – Seun S. Lawal Jan 30 '19 at 07:38
  • A Warning on this answer. The `git rm -r --cached .` followed by `git add .` will first reset all your project's files and the warning goes on `git add .` because you might be adding files that aren't ready to commit and push. Do a `git reset .` and then `git status` to check if all the files are ready to add, commit and push. – McRui Aug 26 '21 at 15:51
28

if you do any changes on git ignore then you have to clear you git cache also

> git rm -r --cached . 
> git add . 
> git commit -m 'git cache cleared'
> git push

if want to remove any particular folder or file then

git rm  --cached filepath/foldername
Akshay Kumar
  • 5,740
  • 2
  • 12
  • 19
8

after that change in git-ignore file run this command , This command will remove all file cache not the files or changes

git rm -r --cached .

after execution of this command commit the files

for removing single file or folder from cache use this command

git rm --cached filepath/foldername

Akshay
  • 127
  • 1
  • 6
7
git rm --cached *.FileExtension

This must ignore all files from this extension

slfan
  • 8,950
  • 115
  • 65
  • 78
Allan Ferraz
  • 71
  • 1
  • 1
3

To remove cached .idea/ directory. e.g. git rm -r --cached .idea

Max Droid
  • 924
  • 9
  • 10