git 清除git本地缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41863484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clear git local cache
提问by jozenbasin
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.
我有一个即将提交的 Webstorm 项目,但在按下 Git Windows GUI 中的提交按钮之前,我记得我不想提交我的.idea
文件夹内容。
So I used the website that auto generates .gitignores
for certain IDEs and added it to my .gitignore
file.
所以我使用了.gitignores
为某些 IDE自动生成的网站并将其添加到我的.gitignore
文件中。
All .idea
files that are explicitly ignored are still showing up to commit, despite me removing and re-added the files in question.
.idea
尽管我删除并重新添加了有问题的文件,但所有被明确忽略的文件仍然显示为提交。
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.
我还提交了没有任何其他文件的 gitignore 文件,并重新粘贴了我的内容,但它仍然没有忽略 .idea 文件。
How do I tell Git to refresh or clear its cache?
I tried /cd ing into the directory in question, and typing
如何告诉 Git 刷新或清除其缓存?
我尝试 /cd 进入有问题的目录,然后输入
git clean -n
git clean -n
but no files show up.
但没有文件显示。
回答by CodeWizard
All .idea files that are explicitly ignored are still showing up to commit
所有被明确忽略的 .idea 文件仍然显示为提交
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.
现在您必须提交这些更改,从现在开始它们将被忽略。
一旦 git 开始跟踪更改,即使它们.gitignore
稍后被添加到文件中,它也不会“停止”跟踪它们。
You mustexplicitly remove them and then commit your removal manually in order to fully ignore them.
您必须明确删除它们,然后手动提交删除以完全忽略它们。
回答by Kamal Kumar
When you think your git is messed up, you can use this command to do everything up-to-date.
当您认为您的 git 搞砸了时,您可以使用此命令来更新所有内容。
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
回答by Allan Ferraz
git rm --cached *.FileExtension
This must ignore all files from this extension
这必须忽略来自此扩展名的所有文件
回答by Akshay
after that change in git-ignore file run this command , This command will remove all file cache not the files or changes
在 git-ignore 文件中的更改后运行此命令,此命令将删除所有文件缓存而不是文件或更改
git rm -r --cached .
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
git rm --cached 文件路径/文件夹名
回答by Max Droid
To remove cached .idea/ directory.
e.g. git rm -r --cached .idea
删除缓存的 .idea/ 目录。例如git rm -r --cached .idea