What is HEAD in Git?

后端 未结 22 2463
野的像风
野的像风 2020-11-22 10:02

You see the Git documentation saying things like

The branch must be fully merged in HEAD.

But what is Git HEAD exac

22条回答
  •  广开言路
    2020-11-22 10:44

    I'd just like to detail a few things in Greg Hewgil's accepted answer. According to the Git Pocket Guide

    Branch:

    the branch itself is defined as all points reachable in the commit graph from the named commit (the “tip” of the branch).

    HEAD: A special type of Ref

    The special ref HEAD determines what branch you are on...

    Refs

    Git defines two kinds of references, or named pointers, which it calls “refs”:

    • A simple ref, which points directly to an object ID (usually a commit or tag)
    • A symbolic ref (or symref), which points to another ref (either simple or symbolic)

    As Greg mentioned, HEAD can be in a "detached state". So HEAD can be either a simple ref (for a detached HEAD) or a symref.

    if HEAD is a symbolic ref for an existing branch, then you are “on” that branch. If, on the other hand, HEAD is a simple ref directly naming a commit by its SHA-1 ID, then you are not “on” any branch, but rather in “detached HEAD” mode, which happens when you check out some earlier commit to examine.

提交回复
热议问题