Git 无法忽略 Visual Studio 中的 node_modules

Git cannot ignore node_modules in Visual Studio

场景如下,我的同事已经将 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

注意: node_modules目录在Repo\Comaps\Compas_ng\Compas_ng文件夹中,是解决方案中的web应用. gitignore 文件位于父目录 Repo\Compas 中。

但是,当再次同步时,node_modules 仍然出现在更改选项卡中。

我应该怎么做才能解决这个问题?以及为什么这些选项对我不起作用。

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

git rm --cached -r node_modules