What is the difference between git reset - file_name and git reset HEAD file_name?

6

To remove files from the 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 the command.

When I did this 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 the staged area. Both commands perform the same action, but are there any differences between them?

    
asked by anonymous 05.08.2018 / 00:34

2 answers

1

There is no difference between the commands below.

git reset HEAD <file_name>
git reset <file_name>

What happens is that if you do not mention HEAD , Git will default to HEAD . This is described in documentation :

  

The% of% defaults to HEAD in all forms.

I believe that in most places staff always pass the command with the <tree-ish>/<commit> parameter to make the explanation more instructive and not to create confusion about where the command is actually being applied.

About using the hyphen double HEAD (double dash or double hyfhen ), is to undo an ambiguity if there is a file and a branch with the same name :

criar-usuario     # arquivo
criar-usuario     # branch

If the file starts with a hyphen, the use of -- is also required.

    
08.08.2018 / 13:32
-1

git reset allows you to specify the commit. This is what you are specifying in HEAD, since HEAD is the most recent commit. It could be any other commit from the past.

    
05.08.2018 / 02:46