If I use:
$ git reset --hard HEAD~N
or
$ git checkout HEAD~N
Both of two will use the version of HEAD~N
to change working directory and stage area.
If there is any different between these two commands?
Thanks.
git checkout HEAD~N
is meant to examine the commit and not to be worked on as it will create a detached head state. If you want to reset (the current branch head) to a particular commit, you use git reset [--hard]
git reset --hard
will reset the current branch HEAD to the specified refspecgit checkout
will switch branch, and leave you in a detached head mode.So with the first, you can start committing right away, in your current branch.
With the second, you need to define a branch first, you (previously) current branch HEAD hasn't move. Only the working directory has been changed. And you are no longer in any branch (hence the "detached mode").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With