如何从git中的索引中删除文件? [英] How to remove a file from the index in git?

查看:576
本文介绍了如何从git中的索引中删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件从索引(= staging area = cache)中删除而不从文件系统中删除它?

How to remove a file from the index ( = staging area = cache) without removing it from the file system?

推荐答案

你想要:

You want:

git rm --cached [file]

如果省略 --cached 选项,它也会从工作树中删除它。 git rm git reset 安全得多,因为如果暂存的内容不符合分支的尖端或磁盘上的文件。 (如果没有,你必须添加 - force 。)

If you omit the --cached option, it will also delete it from the working tree. git rm is slightly safer than git reset, because you'll be warned if the staged content doesn't match either the tip of the branch or the file on disk. (If it doesn't, you have to add --force.)

这篇关于如何从git中的索引中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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