如何从Git的临时区域删除单个文件,但不从索引中删除它或撤消文件本身的更改? [英] How do I remove a single file from the staging area of Git but not remove it from the index or undo the changes to the file itself?

查看:155
本文介绍了如何从Git的临时区域删除单个文件,但不从索引中删除它或撤消文件本身的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:情况:我有一个Git仓库,其中的文件已经在索引中。我修改了几个文件,打开Git并使用git add将这些文件添加到我的临时区域。



问题:从暂存区域删除其中一个文件,但不从索引中删除它或撤消对文件本身的更改? 解决方案

如果我正确地理解了这个问题,你只需要撤销为该文件完成的 git add



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

git reset HEAD - < ; file>



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



git reset HEAD - < directoryName>



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

请参阅< a href =http://schacon.github.com/git/git-reset.html =noreferrer> git reset 手册页 for详情。


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?

解决方案

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>

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

See the git reset man page for details.

这篇关于如何从Git的临时区域删除单个文件,但不从索引中删除它或撤消文件本身的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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