Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unstaging a file with git reset without specifying HEAD

Tags:

git

When unstaging a file in git, the recommended way is to do:

git reset HEAD <file>

However, I find that this also works:

git reset <file>

Why is HEAD needed in the first case, if the second one appears to also work and is shorter to type?

like image 513
void.pointer Avatar asked Oct 21 '22 16:10

void.pointer


2 Answers

It isn't. According to this git-reset documentation:

The <commit> defaults to HEAD in all forms.

like image 156
Alon Gubkin Avatar answered Oct 24 '22 10:10

Alon Gubkin


The man-page clearly states that "The <tree-ish>/<commit> argument defaults to HEAD in all forms." So the second form is equivalent to the first. If you are wondering why git status recommends the second form it seems to make sense to me to provide a full version without using any defaults, especially for new users. But your view of didactic might be different.

like image 42
pmr Avatar answered Oct 24 '22 11:10

pmr