在git,vscode终端中删除node_modules时出错
>git rm -r --cached node_modules
Run Code Online (Sandbox Code Playgroud)
错误:
致命的:pathspec'node_modules'与任何文件都不匹配
小智 74
git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push
`小智 40
我遇到了同样的问题。执行以下步骤 -
在终端中运行以下命令
git rm -r --cached node_modules
git commit -am "node_modules be gone!"
git push origin master
就这样!
你已准备好出发!
Ank*_*dal 19
.gitignore在您的项目目录中制作文件。
.gitignore 文件看起来像这样
/Folder_name
Run Code Online (Sandbox Code Playgroud)
在终端或等效命令中输入以下命令:
git rm -r --cached Folder_name (remove the directory from git but not delete it from the filesystem/locally)
git commit -m "remove unused directory"
git push origin <your-git-branch> (can be master or develop or others)
Run Code Online (Sandbox Code Playgroud)
创建.gitignore文件并在node_modules那里添加:
touch .gitignore && echo "node_modules" >> .gitignore
Run Code Online (Sandbox Code Playgroud)
删除缓存数据:
git rm -r --cached .
Run Code Online (Sandbox Code Playgroud)
更新您的最后一次提交:
git add .
git commit --amend --no-edit
git push --force-with-lease
Run Code Online (Sandbox Code Playgroud)
该错误表示node_modules目录不受 git 版本控制。有2种可能:
它们还没有添加到Git。尝试运行git status命令,看看它们是否显示为untracked文件。
它已经添加到您的gitignore文件中。要列出所有被忽略的文件,请尝试以下命令:git ls-files --others -i --exclude-standard
请注意,当前接受的答案不会完全删除它,它将保留在历史记录中。如果您希望将其从历史记录中完全删除,即从该目录存在的所有过去提交中删除,您可以使用以下方法之一:
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch node_modules" HEAD
Run Code Online (Sandbox Code Playgroud)
(在这里阅读更多相关内容:7.6 Git 工具 - 重写历史)
或者,您可以使用名为filter repo的第三方插件- 这确实也是 Git 官方推荐的方法:
git filter-repo --path node_modules --invert-paths
Run Code Online (Sandbox Code Playgroud)
然而,在这两种情况下,请注意您正在重写历史,这在团队中工作时可能是一场噩梦......。因此,要么在您自己的本地分支/环境中使用它,要么确保您知道没有人有更好的选择,并提前让您所有的伙伴知道这一点。
小智 5
创建文件.gitignore
将行添加node_modules/* 到gitignore文件
在您的终端中运行以下命令
git rm -r --cached node_modules
git add .
git commit -m "Remove node_modules from git in vscode"
git push
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17248 次 |
| 最近记录: |