【问题标题】:Pushed node_modules but cant figure out how to remove推送了 node_modules 但无法弄清楚如何删除
【发布时间】:2020-03-16 14:21:57
【问题描述】:

我将节点模块推送到 GitHub,然后意识到我没有 .gitignore

我添加了gitignore,但它没有解决问题。
我在这里找到了答案,说要用git rm -r --cached node_modules 从缓存中删除它,但这不起作用,因为它说它找不到该文件,我仍然可以在我的仓库中看到它。

我的文件结构是 repo,然后是一个 dev 文件夹,其中包含 node_modules,以及我编写的所有其他代码。
.gitignore 位于 dev 文件夹之外,位于 README 文件旁边。

我是否需要为.gitignore 提供一个路径来查找./node_modules 之类的模块?

【问题讨论】:

    标签: node-modules gitignore


    【解决方案1】:

    gitignore 位于 readme 文件旁边的 dev 文件夹之外

    那么,它应该包括:

    dev/node_modules/
    

    这将忽略dev/node_modules 文件夹及其内容。

    检查(在你的仓库的根文件夹完成git rm --cached dev/node_modules 之后):

    git check-ignore -v -- dev/node_modules/afile
    

    (在 dev/node_modules/ 文件夹内的一个现有文件上测试它)

    【讨论】:

      【解决方案2】:

      如果您在 .gitignore 文件中仅添加了 node_modules,那么它将忽略 repo 中的所有 node_modules 目录。所以你对 .gitignore 配置很好。

      问题是您在删除 node_modules 的缓存副本时应该使用正确的路径。它应该从您的存储库的根目录如下。

      git rm -r --cached ./dev/node_modules

      【讨论】:

        【解决方案3】:

        在 .gitignore 中添加这个

        dev/node_modules/
        

        现在重置缓存。

        git rm -r --cached .
        git add .
        git commit -m ".gitignore is now working"
        

        【讨论】:

          猜你喜欢
          • 2018-08-11
          • 1970-01-01
          • 2019-05-27
          • 2014-12-18
          • 2021-06-25
          • 2013-11-05
          • 1970-01-01
          • 2013-05-19
          • 1970-01-01
          相关资源
          最近更新 更多