如何从Git仓库删除文件?git rm提示文件不存在的问题排查
Hey Ray, I see exactly what's going on here—let's get this fixed right away!
Looking at your terminal output, the issue is super straightforward: you're using the wrong filename in your git rm commands. Let's break it down:
D:\ray\dev\ml\titanic>git rm .ipynb_checkpoints/tryunitesting.ipynb fatal: pathspec '.ipynb_checkpoints/tryunitesting.ipynb' did not match any files D:\ray\dev\ml\titanic>git rm .ipynb_checkpoints\tryunitesting.ipynb fatal: pathspec '.ipynb_checkpoints\tryunitesting.ipynb' did not match any files D:\ray\dev\ml\titanic>ls .ipynb_checkpoints tryunitesting-checkpoint.ipynb
When you listed the contents of .ipynb_checkpoints, the actual filename is tryunitesting-checkpoint.ipynb—but you were trying to delete tryunitesting.ipynb (you missed the -checkpoint suffix). That's why Git couldn't locate the file you were targeting.
The Correct Command
Run either of these commands (both slash styles work on Windows) to delete the file:
git rm .ipynb_checkpoints/tryunitesting-checkpoint.ipynb # Or using backslash: git rm .ipynb_checkpoints\tryunitesting-checkpoint.ipynb
This will remove the file from Git's tracking and delete it from your working directory. If you want to keep the local file but stop tracking it in Git, add the --cached flag like this:
git rm --cached .ipynb_checkpoints/tryunitesting-checkpoint.ipynb
内容的提问来源于stack exchange,提问作者Ray Tayek

