Reputation: 7317
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 A
.
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")?
Upvotes: 1
Views: 116
Reputation: 2883
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~3
change HEAD and master to refer to the same commit.
Upvotes: 2
Reputation: 6476
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 HEAD
and master
point at the same commit
Upvotes: 0