git rm --cached <filename>是否会删除工作区文件?附实操流程
Does
git rm --cached <filename> delete the file from my working directory? Great question — let's cut straight to the chase: Absolutely not. This command only removes the file from Git's index (the staging area that tracks which files Git cares about), leaving your actual working directory file completely intact.
Let's walk through your exact workflow to confirm this behavior:
- You started with
~/Desktop/git_queon branchbrA, with filesbook.json,README.md,SUMMARY.mdin your working directory. - You added
README.mdto.gitignoreto tell Git to ignore it going forward. - When you ran
git rm --cached README.md, the outputrm 'README.md'refers to removing the file from Git's tracked index, not deleting it from your filesystem. - After staging the changes with
git add .and checkinggit status, the "deleted: README.md" entry in your staged changes is Git recording that it's no longer tracking this file — not that the file was erased from your working directory.
If you run ls again in your working directory right now, you'll still see README.md sitting there. The command only modifies Git's internal tracking state, not your local files.
内容的提问来源于stack exchange,提问作者SEGV
相关产品推荐
相关产品推荐

