Clear git local cache
Asked Answered
A

8

165

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.

Anfractuous answered 25/1, 2017 at 23:19 Comment(0)
B
258

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

Bridie answered 25/1, 2017 at 23:27 Comment(6)
I never commit the files I'm trying to ignore, though.. This tells me fatal: pathspec '.idea' did not match any filesAnfractuous
When you type git status do you see them? WebStorm might have added them for you if you marked the checkbox to auto add filesBridie
I have no idea but it seems the command you gave me worked, even though it returned a fatal error.... The files no longer show up to commit.Anfractuous
you might consider adding -r for recursive removingFrisk
For me i had to include -r like git rm --cached -r .ideaStocky
For me git rm -rf --cached .Asyut
Q
197

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
Quach answered 9/2, 2018 at 9:57 Comment(3)
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"Machellemachete
the reset part was at best confusing. but I did up to 'git push', and was fine.Leander
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.Biofeedback
L
34

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
Logistician answered 7/8, 2019 at 11:27 Comment(0)
B
10

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

Blamable answered 26/1, 2020 at 19:39 Comment(0)
L
7
git rm --cached *.FileExtension

This must ignore all files from this extension

Largescale answered 1/3, 2019 at 15:51 Comment(0)
B
3

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

Buryat answered 21/10, 2019 at 18:30 Comment(0)
W
1

You can try with :

$ git clean -d -n

afterward it will show you what it will delete if that's what you want to do :

git clean -f -d
Wuhan answered 5/11, 2023 at 19:41 Comment(0)
W
-1

first

(git clone <url repos>)

second

cut all files to another folder

run these codes one by one

git rm --cached star.star (shift+8)

git add .

git commit -m "first commit"

git branch -M main

git remote add origin (url your repos)

git push -u origin main

then rpose cleared 

Waterfront answered 5/3 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.