0

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.

John Reed Avery
  • 121
  • 1
  • 7
  • `--` has a standardized meaning in Unix-like command lines, regardless of what the program is. Here it's simply to make sure that Git doesn't treat the `` as a commit ID (i.e. the point to `reset` to). – Karl Knechtel Mar 09 '23 at 16:55
  • Does this answer your question? [In plain English, what does "git reset" do?](https://stackoverflow.com/questions/2530060/in-plain-english-what-does-git-reset-do) – Karl Knechtel Mar 09 '23 at 16:56
  • Hey, Karl. Your top explanation makes sense, except that it still does not clarify the contrast of using "HEAD" instead of "--" (or vice versa). Also, I already checked out that 'In plain English" post: I did not find it to be helpful. Thanks. --JRAvery – John Reed Avery Mar 09 '23 at 19:31
  • Let me try this again: I find the "**In plain English**" page unhelpful because it has gobs of info that I do not understand as pertaining to my question. Many other people no doubt get it but I believe that this is because they understand Git/Gitlab/Github **so well** that they see insight, in those words, that is not clear to those of us who do not have the same level of Git-brilliance. So, please let me rephrase this way: **IF** "**git reset -- filename**" and "**git reset HEAD filename**" do exactly the same thing then please simply say so. Else, please explain. Thanks. – John Reed Avery Mar 09 '23 at 23:27
  • One other point of clarification, regarding my above comment: The "**In plain English**" page has **only 1** example of using "**git reset -- *[something]***", **BUT** that example is contrasted with simply using "**git reset**", with no other options or arguments. To my feeble brain, this does not help me to understand the contrast to "**git reset HEAD *[something]***". I apologize if this is obvious to everybody else but me. Thanks. – John Reed Avery Mar 09 '23 at 23:33
  • 1
    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 `` is actually a filename. Applying logical reasoning: with `git reset -- `, 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 Mar 10 '23 at 01:08
  • That was the first reference I could find; I don't normally look at Git questions much, but this is a fairly fundamental concept and there are a few super-popular answers. If the question is more about how `--` works, I don't know if we have a canonical for that, but it might be something better answered on e.g. [unix.se] or https://superuser.com. – Karl Knechtel Mar 10 '23 at 01:10

1 Answers1

0

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 is actually a filename. Applying logical reasoning: with git reset -- , 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!

John Reed Avery
  • 121
  • 1
  • 7