Git无法在Visual Studio中忽略node_modules文件夹。

3

这是一个场景,我的同事已经将他的node_modules文件夹推送到远程仓库。

在我的电脑上,我运行了"npm_install"命令来安装所有必需的依赖项。现在,当我尝试同步远程仓库以获取新更改时,我收到了这个消息:

 Cannot pull because there are uncommitted changes.
 Commit or undo your changes before pulling again. See the Output window for details.

在更改选项卡中:我的 node_modules 目录已包含。因此,我需要将其忽略。
我尝试了以下操作:
  1. 在 tsconfig.ts 中添加:"exclude": ["node_modules"]
  2. 将 "node_modules" 添加到 gitignore 中。

enter image description here

注意:node_modules目录位于Repo\Comaps\Compas_ng\Compas_ng文件夹中,该文件夹是解决方案中的Web应用程序。gitignore文件位于父级目录Repo\Compas中。

enter image description here

但是,当再次同步时,node_modules仍然出现在更改选项卡中。
我应该怎么做才能解决这个问题?为什么选项对我没有起作用?
1个回答

3

您需要清除node_modules文件夹的缓存:

git rm --cached -r node_modules

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接