1

Must HEAD point to a branch, or can it point directly to a commit node? Is it possible to move HEAD to point to an arbitrary commit node even if no branch is referencing this node?

Evan Aad
  • 5,699
  • 6
  • 25
  • 36

2 Answers2

3

Must HEAD point to a branch, or can it point directly to a commit?

HEAD is just a pointer to a commit. It is possible that no branch points to that commit.

Is it possible to move HEAD to point to an arbitrary commit even if no branch is referencing this commit?

Yes, it is. Just do:

git checkout <commit-sha>

and you will check out that commit in a detached head state. That basically means that you are currently not on a branch.

Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
1

Read this full answer:

How to move HEAD back to a previous location? (Detached head)

HEAD can be point to any commit, If HEAD is not pointing to a the latest commit in the branch you are in a detached HEAD.

Read the above answer to get the full detailed what is it and how to "fix" it.

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167