What is HEAD in Git?

后端 未结 22 1993
野的像风
野的像风 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:43

    HEAD is just a special pointer that points to the local branch you’re currently on.

    From the Pro Git book, chapter 3.1 Git Branching - Branches in a Nutshell, in the section Creating a New Branch:

    What happens if you create a new branch? Well, doing so creates a new pointer for you to move around. Let’s say you create a new branch called testing. You do this with the git branch command:

    $ git branch testing 
    

    This creates a new pointer at the same commit you’re currently on

    enter image description here

    How does Git know what branch you’re currently on? It keeps a special pointer called HEAD. Note that this is a lot different than the concept of HEAD in other VCSs you may be used to, such as Subversion or CVS. In Git, this is a pointer to the local branch you’re currently on. In this case, you’re still on master. The git branch command only created a new branch — it didn’t switch to that branch.

    enter image description here

提交回复
热议问题