`git reset HEAD file` 是否也检查文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6790194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does `git reset HEAD file` also check out the file?
提问by Eternal Learner
I mistakenly added a directory to git and when I followed the tip hereto undo the add by doing git reset HEAD <file>
, I was horrified to discover that the current working copy of one of the files, which has lots of changes (work!) in it, reverted backto the previous version!
我错误地向 git 添加了一个目录,当我按照此处的提示通过执行来撤消添加时git reset HEAD <file>
,我惊恐地发现其中一个文件的当前工作副本(其中有很多更改(工作!))恢复了回到以前的版本!
As a result I lost several hours worth of work... :((
结果我失去了几个小时的工作...... :((
I thought that git reset HEAD <file>
only "removes it from the current index without changing anything else. What did I miss?
我认为这git reset HEAD <file>
只是“将其从当前索引中删除而不更改任何其他内容。我错过了什么?
Is git reset HEAD <file>
supposed to also check outthe file from HEAD?
是git reset HEAD <file>
应该还检查了从头部文件?
How can I minimize the chances of something like this happening again in the future?
我怎样才能最大程度地减少将来再次发生类似事情的机会?
回答by demental
Only git checkout -- <file>
should have reverted the files in their previous stats.
git reset HEAD <file>
should only unstage the file, not revert its content.
只git checkout -- <file>
应该恢复以前统计中的文件。
git reset HEAD <file>
应该只取消暂存文件,而不是还原其内容。
回答by Rafa? Rawicki
git reset
unstages files from index. Maybe you added --hard
option or used git checkout
afterwards?
git reset
从索引取消暂存文件。也许您添加了--hard
选项或git checkout
之后使用?
Quoting the git-reset manpage:
引用 git-reset 联机帮助页:
git reset [-q] [<commit>] [--] <paths>... This form resets the index entries for all to their state at . (It does not affect the working tree, nor the current branch.)
git reset [-q] [<commit>] [--] <paths>... 这种形式将所有的索引条目重置为它们在 的状态。(它不影响工作树,也不影响当前分支。)