One of the primary purposes for HEAD
is that it becomes the parent commit of any new commits you create. Typically the HEAD
reference takes one of two forms - either a symbolic reference to a branch tip (e.g. master
) or the hash of a specific commit. The first is the "normal" mode of operation, and a new commit results in 1) the parent of the new commit being set to the hash represented by the current HEAD
, and 2) the branch reference that is the current target of the HEAD
reference being moved to point to the new commit. The second case is called "detached", because your HEAD
reference is not currently attached to a branch, but to a specific commit that may or may not be a branch tip. This is not a problem, but is just a reminder to you that, because you do not have a branch to update if you create a new commit, any new commits you do make will have nothing except HEAD
pointing at them. If you then check out a different branch, there is nothing at all pointing at the new commits, so you run the risk of losing them (there's still the HEAD
reflog, so you can generally recover even then, though).
So, the short answer is, no, there is no way to check out an arbitrary non-branch-tip commit without either detaching the HEAD
or creating a new branch (but if you're just wanting to look at something on an older commit, that doesn't make sense, because you'll end up with many not-useful branches cluttering up your namespace. There's no harm in having HEAD
detached, and it's a normal way of working within git
. It just reminds you when you do things like git status
so that you can keep in mind what you're in the middle of...