从 Git 存储库中删除文件而不从本地文件系统中删除它 [英] Remove a file from a Git repository without deleting it from the local filesystem

查看:19
本文介绍了从 Git 存储库中删除文件而不从本地文件系统中删除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的初始提交包含一些日志文件.我已将 *log 添加到我的 .gitignore,现在我想从我的存储库中删除日志文件.

My initial commit contained some log files. I've added *log to my .gitignore, and now I want to remove the log files from my repository.

git rm mylogfile.log

将从存储库中删除文件,但也会从本地文件系统中删除它.

will remove a file from the repository, but will also remove it from the local file system.

如何从存储库中删除此文件而不删除文件的本地副本?

How can I remove this file from the repo without deleting my local copy of the file?

推荐答案

来自 man 文件:

当给定 --cached 时,暂存内容必须匹配分支的尖端或磁盘上的文件,允许仅从索引中删除文件.

When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

所以,对于单个文件:

git rm --cached mylogfile.log

对于单个目录:

git rm --cached -r mydirectory

这篇关于从 Git 存储库中删除文件而不从本地文件系统中删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆