What’s the difference between git reset -- <file_name> and git reset HEAD <file_name>?

Asked

Viewed 217 times

6

To remove files from staged area I use the command:

 $ git reset HEAD <file_name>

However I accidentally applied the command:

$ git reset <file_name>

I forgot the HEAD of command.

In doing so I got the message:

fatal: ambiguous argument 'class/control/C_usuarioferias.php': Unknown Revision or path not in the Working Tree. Use '-' to Separate paths from revisions, like this: 'git [...] -- [...]'

I interpreted the same and then applied the command:

$ git reset -- <file_name>

So the file has been removed from staged area. Both commands perform the same action, but there is some difference between them?

2 answers

2


There is no difference between the commands below.

git reset HEAD <file_name>
git reset <file_name>

What happens is that if you don’t mention the HEAD, Git will use by default HEAD. This is described in documentation:

The <tree-ish>/<commit> defaults to HEAD in all Forms.

I believe that in most places the staff always passes the command with the parameter HEAD to leave the explanation more didactic and not create confusion about where the command is being applied in truth.

About the use of double hyphen -- (double Dash or double hyfhen), is to undo an ambiguity if there is a file and a branch by the same name:

criar-usuario     # arquivo
criar-usuario     # branch

If the file starts with hyphenation, use the -- it is also necessary.

-1

Git reset allows you to specify the commit. That’s what you’re specifying in HEAD, because HEAD is the latest commit. It could be any other commit from the past.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.