您可以看到Git文档中这样说
分支必须在HEAD中完全合并。
但Git HEAD到底是什么?
您可以看到Git文档中这样说
分支必须在HEAD中完全合并。
但Git HEAD到底是什么?
当前回答
引用别人的话:
A head is simply a reference to a commit object. Each head has a name (branch name or tag name, etc). By default, there is a head in every repository called master. A repository can contain any number of heads. At any given time, one head is selected as the “current head.” This head is aliased to HEAD, always in capitals". Note this difference: a “head” (lowercase) refers to any one of the named heads in the repository; “HEAD” (uppercase) refers exclusively to the currently active head. This distinction is used frequently in Git documentation.
可以在这里找到另一个很好的源代码,它可以快速覆盖git的内部工作原理(因此可以更好地理解heads/HEAD)。引用(ref:)或头或分支可以被看作是粘贴在提交历史记录中的提交上的便利贴。通常它们指向一系列提交的提示,但它们可以随着git checkout或git reset等移动。
其他回答
看看http://git-scm.com/book/en/Git-Branching-What-a-Branch-Is
图3 - 5。HEAD文件指向你所在的分支。
Head指向当前签出分支的顶端。
在您的存储库中,有一个.git文件夹。在这个位置打开文件:.git\refs\heads。该文件(在大多数情况下是master)中的(sha-1哈希)代码将是最近的提交,即在命令git日志的输出中看到的代码。关于.git文件夹的更多信息:http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html
Git都是关于提交的。 Head指向当前签出的提交。
$ git cat-file -t HEAD
commit
无论何时签出一个分支,HEAD都指向该分支上的最新提交。HEAD的内容可检查如下(主分支):
$ cat .git/refs/heads/master
b089141cc8a7d89d606b2f7c15bfdc48640a8e25
要把正确答案中的要点讲清楚,一个很好的方法就是跑步 git reflog HEAD,你会得到HEAD所指向的所有地方的历史。
假设这不是一种叫做“分离HEAD”的特殊情况,那么,正如O'Reilly Git书第2版第69页所述,HEAD的意思是:
HEAD总是指当前节点上最近的提交 分支。当您更改分支时,HEAD将被更新为引用新的分支 布兰奇的最新提交。
so
HEAD是当前分支的“尖端”。
注意,我们可以使用HEAD表示最近的提交,使用HEAD~表示提示之前的提交,使用HEAD~~或HEAD~2表示更早的提交,以此类推。