您可以看到Git文档中这样说
分支必须在HEAD中完全合并。
但Git HEAD到底是什么?
您可以看到Git文档中这样说
分支必须在HEAD中完全合并。
但Git HEAD到底是什么?
当前回答
您可以将HEAD视为“当前分支”。当您使用git签出切换分支时,HEAD修订将更改为指向新分支的尖端。
你可以通过这样做来查看HEAD指向什么:
cat .git/HEAD
在我的例子中,输出是:
$ cat .git/HEAD
ref: refs/heads/master
HEAD可以引用与分支名称不关联的特定修订。这种情况被称为分离HEAD。
其他回答
您可以将HEAD视为“当前分支”。当您使用git签出切换分支时,HEAD修订将更改为指向新分支的尖端。
你可以通过这样做来查看HEAD指向什么:
cat .git/HEAD
在我的例子中,输出是:
$ cat .git/HEAD
ref: refs/heads/master
HEAD可以引用与分支名称不关联的特定修订。这种情况被称为分离HEAD。
作为一个概念,头是分支中的最新修订。如果每个命名分支有多个头,那么在进行本地提交时可能会创建它,而没有合并,这实际上创建了一个未命名的分支。
为了拥有一个“干净的”存储库,每个命名分支都应该有一个头,并且在本地工作后总是合并到一个命名分支。
Mercurial也是如此。
HEAD只是一个特殊的指针,它指向您当前所在的本地分支。
从Pro Git书籍3.1章Git分支-果壳中的分支,在部分创建一个新的分支:
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 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.
感觉HEAD只是您签出的最后一次提交的标记。
这可以是一个特定分支的顶端(例如“master”),也可以是某个分支的中间提交(“detached head”)。
HEAD实际上只是一个存储当前分支信息的文件
如果你在git命令中使用HEAD,你就指向了当前的分支
您可以通过查看该文件的数据 猫. /头