git删除本地文件但将文件保留在repo中

标签 git github

尝试在本地删除文件,同时将文件保留在存储库中。问题是我似乎无法丢弃已删除的内容。我尝试使用 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/

相关文章:

git - 避免在 BitBucket 管道中使用 Master 分支

Git:将本地目录置于版本控制之下

git grep : Sometimes empty result even when the word exists in a file

linux - `gh cli` 失败 `git@github.com: Permission denied (publickey)` 但 `gh desktop` 没有问题

github - 是否可以在 github 的不同文件夹中创建和组织要点?

git - 如何从命令提示符打开 git 配置文件 - git shell?

git - 如何删除从 .git 中删除的文件?

git - 删除完整的 Git 历史而不删除存储库?

python - 使用 PyCharm 从 GitHub 安装 Python 包

Git 推送错误 :RPC failed; curl 55 SSL_write() returned SYSCALL, errno = 10053。互联网连接正常,尝试增加缓冲区大小