在 vscode 中从 git 中删除 node_modules
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50675829/
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
Remove node_modules from git in vscode
提问by Mano
Getting error while removing node_modules in git, vscode terminal
在 git、vscode 终端中删除 node_modules 时出错
>git rm -r --cached node_modules
Error:
错误:
fatal: pathspec 'node_modules' did not match any files
致命:路径规范“node_modules”与任何文件都不匹配
回答by Karavolt
- make .gitignore file.
- add node_modules/ line to gitignore file
- run this command
git rm -r --cached . git add . git commit -m "remove gitignore files" git push
- 制作 .gitignore 文件。
- 将 node_modules/ 行添加到 gitignore 文件
- 运行这个命令
git rm -r --cached . git add . git commit -m "remove gitignore files" git push
回答by Sheena Singla
I faced the same issue. Do the below steps -
我遇到了同样的问题。执行以下步骤 -
- Make .gitignore file.
Run below commands in your terminal
git rm -r --cached node_modules
git commit -am "node_modules be gone!"
git push origin master
- 制作 .gitignore 文件。
在终端中运行以下命令
git rm -r --cached node_modules
git commit -am "node_modules be gone!"
git push origin master
That's all!
就这样!
You are good to go!
你已准备好出发!
回答by Shuwn Yuan Tee
The error means node_modules
directory is not under git version control. There are 2 possibilities:
该错误表示node_modules
目录不受 git 版本控制。有2种可能:
They are not added to
Git
yet. Try runninggit status
command, to see whether they appear asuntracked
files.It has already been added into your
gitignore
file. To list all ignored files, try this command:git ls-files --others -i --exclude-standard
它们还没有添加到
Git
。尝试运行git status
命令,看看它们是否显示为untracked
文件。它已经添加到您的
gitignore
文件中。要列出所有被忽略的文件,请尝试以下命令:git ls-files --others -i --exclude-standard
回答by Meryan
Once git starts tracking a file or a folder it won't stop even if you add it to .gitignore
一旦 git 开始跟踪文件或文件夹,即使您将其添加到 .gitignore 也不会停止
You will need to delete it from the .git repository. I exclusively use a local one, typically located at the root of the project's source.
您需要从 .git 存储库中删除它。我只使用本地的,通常位于项目源的根目录。
As of today 20200408, it does not appear there is a mouse click approach to remove the annoying file/folder from git.
截至今天 20200408,似乎没有鼠标单击方法可以从 git 中删除烦人的文件/文件夹。
You will have to use the terminal.
您将不得不使用终端。
Press Ctrl-Jthen select Terminaltab
按Ctrl-J然后选择终端选项卡
or from VSCode menu select Terminal/ New Terminal
或从 VSCode 菜单中选择终端/新终端
Then issue something like the following command
然后发出类似以下命令的内容
git rm -r --cached www/index.html
The following exclude
以下排除
www/
was already in my .gitignore file.
已经在我的 .gitignore 文件中。
In your case you would want to add the "cancer folder" :)
在您的情况下,您需要添加“癌症文件夹”:)
node_modules/
PS: Simple things made unnecessarily hard, I wonder why?
PS:简单的事情变得不必要地困难,我想知道为什么?
Below is the zillion garbage of Git commands I never use. Enjoy!
下面是我从未使用过的无数垃圾 Git 命令。享受!