I have been using
git reset --soft HEAD^ and
git reset --soft HEAD~1 when I want to return my last commit to the staging area. I have been using them interchangeably but was wondering if there were any subtle differences? If there aren't any, can you explain the syntactical difference? Is
^ just an alias for
HEAD~1 refer to the same commit.
^ refers to the first parent of the commit.
~n refers to the n:th ancestor. So
^^ (parent-of-parent) is equivalent to
The main subtlety I can think of is if there is several parents to the current commit (i.e. it is a merge commit). In that case both
HEAD^2 are valid and refer to different commits.
HEAD~1 refers to
HEAD^ but not
The gitrevisions man page has lots of details and examples.
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