如何从临时区域中删除单个文件(撤消git add)? [英] How do I remove a single file from the staging area (undo git add)?

查看:133
本文介绍了如何从临时区域中删除单个文件(撤消git add)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:我有一个Git存储库,其中的文件已经在索引中.我对几个文件进行了更改,打开Git并使用"git add"将这些文件添加到我的暂存区.

Situation: I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."

问题:如何从登台区域中删除其中一个文件,但不从索引中删除它们或撤消对文件本身的更改?

Question: How do I remove one of those files from the staging area but not remove it from the index or undo the changes to the file itself?

推荐答案

如果我正确理解了这个问题,则只想撤消"对该文件执行的git add.

If I understand the question correctly, you simply want to "undo" the git add that was done for that file.

如果您需要从临时区域中删除单个文件,请使用

If you need to remove a single file from the staging area, use

git reset HEAD -- <file>

如果您需要从暂存区中删除整个目录(文件夹),请使用

If you need to remove a whole directory (folder) from the staging area, use

git reset HEAD -- <directoryName>

您的修改将被保留.当您运行git status时,文件将再次显示为已修改但尚未暂存.

Your modifications will be kept. When you run git status the file will once again show up as modified but not yet staged.

有关详细信息,请参见 git reset手册页.

See the git reset man page for details.

这篇关于如何从临时区域中删除单个文件(撤消git add)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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