如何从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?
问题描述
问题:从暂存区域删除其中一个文件,但不从索引中删除它或撤消对文件本身的更改? 解决方案
如果我正确地理解了这个问题,你只需要撤销为该文件完成的 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屋!