简体   繁体   English

列出分支时,Git HEAD与主分支分离

[英]Git HEAD detached from master branch when listing branches

I thought I was understanding HEAD to be the 'current' branch, but when listing branches I see that my current and the remote HEAD are distinct for one of my repos. 我认为我理解HEAD是'当前'分支,但是当列出分支时,我看到我的当前和远程HEAD对于我的一个回购而言是不同的。 The other repository does not even list a remote head branch. 另一个存储库甚至没有列出远程头部分支。 Could someone please explain the following: 有人可以解释一下:

me@portalinux ~/edcourse $ git branch -va
* master                9de94d9 Work on week 3 stuff thursday 
  remotes/origin/HEAD   -> origin/master
  remotes/origin/master 9de94d9 Work on week 3 stuff thursday

As you can see, the origin/HEAD seems to be just pointing at master. 如你所见,原点/ HEAD似乎只是指向主人。 But in the following repo it does not: 但是在下面的回购中它没有:

me@portalinux ~/cpp $ git branch -va
* master             f30bc16 End of chapter 2
  remotes/cpp/master f30bc16 End of chapter 2

The only point of difference between how I've handled the repositories is that the first repository was initialized and updated by two different clients, this second repository has only been updated by one computer. 我处理存储库的唯一区别是第一个存储库是由两个不同的客户端初始化和更新的,第二个存储库只由一台计算机更新。 Will be interested to see whether this second repo gains a remote HEAD pointing at master once I start using a second computer for updates. 有兴趣看看,一旦我开始使用第二台计算机进行更新,第二个repo是否会获得指向master的远程HEAD。

Your idea that HEAD points to the current branch is pretty close, but note that it might not always do so. 你认为HEAD指向当前分支的想法非常接近,但请注意,它可能并不总是如此。 For example, in a "detached head" state it might point at an arbitrary commit. 例如,在“分离头”状态下,它可能指向任意提交。

Shared Git repositories are often implemented as bare repositories , which means they lack a working copy. 共享Git存储库通常实现为存储库 ,这意味着它们缺少工作副本。 Essentially, they exist only as a .git/ directory. 实质上,它们仅作为.git/目录存在。 In the absence of a working copy the concept of a "current branch" lacks meaning, and as a result remotes often don't have a HEAD . 在没有工作副本的情况下,“当前分支”的概念缺乏意义,因此遥控器通常没有HEAD

Some remotes do have a HEAD , for example a non-bare remote would. 有些遥控器确实HEAD ,例如非裸遥控器。 GitHub uses HEAD to identify the "default branch" , a GitHub-specific concept. GitHub使用HEAD来识别“默认分支” ,这是一个特定于GitHub的概念。 Other vendors may follow suit, or use it for something entirely different. 其他供应商可能会效仿,或者将其用于完全不同的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM