git reset vs git reset HEAD

前端 未结 3 556
花落未央
花落未央 2020-11-29 04:56

Every time a file has been staged, Git offers helpful instructions in the event you needed to unstage a file:

(use \"git reset HEAD ...\" to unstag

3条回答
  •  猫巷女王i
    2020-11-29 05:12

    By default, git reset is equivalent to git reset HEAD

    Quoting the man page (my emphasis):

    git-reset - Reset current HEAD to the specified state.

    git reset [-q] [] [--] …
    git reset (--patch | -p) [] [--] […​]
    git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] []
    

    In the first and second form, copy entries from to the index. In the third form, set the current branch head (HEAD) to , optionally modifying index and working tree to match. The / defaults to HEAD in all forms.

    [...]

    git reset [-q] [] [--] …​
    

    This form resets the index entries for all to their state at . (It does not affect the working tree or the current branch.)

    This means that git reset is the opposite of git add .

    From this you see that there's no actual difference in behavior.

    This seems more straightforward, so why the difference?

    Since they're both the same, you might as well use the shortest version of the two.

提交回复
热议问题