尝试在本地删除文件,同时将文件保留在存储库中。问题是我似乎无法丢弃已删除的内容。我尝试使用 git rm
。但是使用 git rm
也会删除 repo 上的副本,这不是我想要的。我能想到的唯一解决方案是将路径放在 .gitignore
中。还有其他解决方案吗?
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
deleted: stuff/code
最佳答案
这不是真正明智的做法,也不是 Git 旨在支持的工作流。
如果你想删除本地文件,但不影响Git,那么你就不能使用Git。只需使用 rm <file>
.丢失的文件将永远显示为 Git 的未暂存更改。
如果你想删除文件并防止 Git 不断将其显示为未暂存的更改,你可以使用
git update-index --assume-unchanged <file>
但同样,您真的不应该这样做。
关于git删除本地文件但将文件保留在repo中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31415032/