英文:
Difference between "git reset HEAD <filename>" and "git reset -- <filename>"?
问题
当我暂存一个文件时,“git status”然后提到,要取消暂存该文件,可以使用“git reset HEAD filename”。但我也见过建议使用“git reset -- filename”的情况。
抱歉,我不记得我何时看到建议使用“--”而不是“HEAD”之间的表面差异,但我刚刚进行了一个测试,尝试取消暂存一个文件两次:一次使用“HEAD”,一次使用“--”,我看不出结果上的区别。
(除非绝对必要,为了给我一个真正准确的答案,我不感兴趣关于“HEAD~”和“HEAD~1”之间的微小差异等等等等的细微差别,因为我似乎很少或从不看到这些微小差别在弹出的自动建议中提到。)
谢谢。
英文:
When I stage a file, "git status" then mentions that, to UNstage that file, I can do "git reset HEAD filename". But I have also seen instances in which the recommended command is "git reset -- filename".
Sorry, I do not remember the superficial differences between when I have seen "--" recommended instead of "HEAD" but I just now ran a test, in which I attempted to UNstage a file 2 separate times: once using "HEAD" and once using "--", and I cannot see the difference in the results.
(Unless it's absolutely necessary, in order to give me a truly accurate answer, I'm not interested in subtleties about the differences between "HEAD~" and "HEAD~1"; etc; etc. --because I seem to rarely-or-never see those subtleties mentioned in the automatic recommendations that pop up.)
Thanks.
答案1
得分: 0
无法确定官方的最佳回答方式来接受Karl Knechtel的第3条评论,所以我添加了这个“回答”来表明:
从顶部的回答中:“如果未提供路径,则将重置整个树,如果未提供提交,则将其视为HEAD(当前提交)。”从我的评论(这是关于与Git无关的一般约定的,使用--表示
谢谢,Karl!
英文:
I can't figure out the official way to accept Karl Knechtel's 3rd comment as the best answer; so, I am adding this "answer" in order to say that:
From the top answer: "If the paths aren't provided, the entire tree is reset, and if the commit isn't provided, it's taken to be HEAD (the current commit)." From my comment (which is supposed to be about general conventions that are not to do with Git): using -- means that <filename> is actually a filename. Applying logical reasoning: with git reset -- <filename>, the commit wasn't provided (the -- was used to make the next thing be a filename instead of a commit); therefore, the commit is taken to be HEAD. I.e.: Yes, it's the same thing. –
Karl Knechtel (13 hours ago)
Thanks, Karl!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论