HEAD always points to the commit that is checked out. HEAD~, which is the same as HEAD~1refers to HEADʼs parent. HEAD~2 is the parent of HEAD~1, and so on.
When you git chegkout a different commit, HEAD moves to that commit. When you git commit your changes, HEAD moves to the newly created commit.
When you do a git log <commitish> (where <commitish> can be a branch name, a tag, a commit hash, or pretty much anything then unambiguously refers to a commit, and defaults to HEAD if you donʼt specify it), Git will print that commit, its parent, the parent of that parent, and so on.
Contrast that to git reflog which displays the commit HEAD is pointing to, then the commit HEAD was pointing before (and can be referred to as HEAD@{1}), and so on.
Hope that helps, happy coding!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
HEAD
always points to the commit that is checked out.HEAD~
, which is the same asHEAD~1
refers toHEAD
ʼs parent.HEAD~2
is the parent ofHEAD~1
, and so on.When you
git chegkout
a different commit,HEAD
moves to that commit. When yougit commit
your changes,HEAD
moves to the newly created commit.When you do a
git log <commitish>
(where<commitish>
can be a branch name, a tag, a commit hash, or pretty much anything then unambiguously refers to a commit, and defaults toHEAD
if you donʼt specify it), Git will print that commit, its parent, the parent of that parent, and so on.Contrast that to
git reflog
which displays the commitHEAD
is pointing to, then the commitHEAD
was pointing before (and can be referred to asHEAD@{1}
), and so on.Hope that helps, happy coding!