Does HEAD always refer to what “master” refers to (in this context)?
Suppose one is on branch “master” and that HEAD is at the tip of the branch (say, on commit
C). Suppose one then executes
git reset --hard HEAD^3 back to commit
A. Then HEAD now refers to
Question: Does “master” also refer to
A, or is it still pointing at
C? Put differently: in this context, does HEAD always refer to what the branch “master” does (i.e., assuming that our repository has only one branch named “master”)?
2 Solutions collect form web for “Does HEAD always refer to what “master” refers to (in this context)?”
Let’s check it, current branch is:
$ git branch * master
current state of the repo:
$ git log --oneline e585b43 C 4bbf8be B 6ae7d39 A fb4949b Initial commit
Let’s rebase it:
$ git reset --hard HEAD~3 HEAD is now at fb4949b Initial commit
Let’s check where HEAD points:
$ git log HEAD --oneline fb4949b Initial commit
Let’s check where master points:
$ git log master --oneline fb4949b Initial commit
As you can see
master point at the same commit
No, HEAD will not always refer to the same commit as “master”.
In case you checkout a commit that has been become dangling HEAD will refer to that commit and “master” will still refere to the tip of that branch.
In this case will
git reset --hard HEAD~3change HEAD and master to refer to the same commit.