Reputation: 9736
I understand that by default unless a previous commit is checked-out, HEAD
is the latest commit on the currently checked-out branch.
What is the difference between:
git reset HEAD
git reset HEAD~
My understanding:
The first command will reset latest commit - why would anyone do this? Unless for example HEAD
is made to point to another place using checkout command prior to running this reset command. Correct?
The second command will reset the commit prior to the head, effectively the latest commit will now be orphaned. Correct?
Upvotes: 1
Views: 68
Reputation: 265928
git reset X
is identical to git reset --mixed X
. Looking at the documentation, that is:
git reset [<mode>] [<commit>]
This form resets the current branch head to
<commit>
and possibly updates the index (resetting it to the tree of<commit>
) and the working tree depending on<mode>
. If<mode>
is omitted, defaults to--mixed
. The<mode>
must be one of the following:
--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
If
-N
is specified, removed paths are marked as intent-to-add (see git-add).
So, git reset --mixed
resets marks all staged changes as unstaged again. git reset --mixed HEAD
is identical. git reset --mixed HEAD^
moves your HEAD back by one (following the first parent).
Executing git reset HEAD^
will lose the commit that was HEAD at the time this command is executed, unless it is reachable from other refs (branches, tags).
Upvotes: 3