【问题标题】:Gitignore not working. Do I have the wrong file path?Gitignore 不工作。我有错误的文件路径吗?
【发布时间】:2023-01-02 23:55:57
【问题描述】:

我有一个如下所示的目录结构:

backend
 - node_modules
 - app.js
.gitignore

我的.gitignore 文件如下所示:

./backend/node_modules

但出于某种原因,我的node_modules 文件夹仍在上传到 Github。知道为什么会这样吗?

【问题讨论】:

  • .gitignore对以下方面没有影响推动.你不能忽略已经是提交的一部分(因此,).如果文件已经跟踪,该文件不会影响它们。他们已经在分支机构中被跟踪了吗?如果是,那么您需要删除它们(继续前进,并将它们保留在历史记录中……或者重写历史记录以将它们从过去的历史记录中删除)。

标签: git github gitignore


【解决方案1】:

使用.gitignore 忽略文件更改仅在文件从未被跟踪时有效(也就是从未使用 git add 添加到 git)。

如果您想完全删除远程更改,请更新 .gitignore 并执行以下命令

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

如果您只是想排除推送更改但不想删除远程节点模块,您可以通过以下命令让 git 假定上述路径不变

git update-index --assume-unchanged ./backend/node_modules

【讨论】:

    猜你喜欢
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2022-01-08
    • 2013-11-27
    • 2013-07-02
    • 2014-12-27
    相关资源
    最近更新 更多