什么决定了“git clone”之后的默认分支? [英] What determines default branch after "git clone"?

查看:685
本文介绍了什么决定了“git clone”之后的默认分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,克隆存储库的默认分支是无论HEAD指向正在克隆的repo中的任何指向。



现在我有一个情况,这是不对。我的理解显然是有缺陷的,那么克隆一个(裸)回购时确定默认checkout分支是什么?



该回购的最后一次提交是分支引用在裸露的repo的HEAD到分支中,我将作为克隆中的checkout分支。



运行 git remote show origin 返回:

 抓取网址:... 
推送网址:...
HEAD分支(远程HEAD不明确,可能是以下之一):
< bad-branch>
live
远程分支:
...

裸回购使用Git版本1.8.2.1,客户端使用1.7.12.4,传输是SSH。

也许答案实际上是 here this here 此答案证实了它。如果有符号引用选项都指向与HEAD相同的版本,则客户端会猜测要使用哪个分支。

解决方案

Git 1.8.5 ,服务器会发送指向的 HEAD 指向的实际分支名称能力。如果你的客户端和服务器都比Git 1.8.5更新,它会正确更新 HEAD



在此之前,客户端将通过比较HEAD(最终)指向的对象ID与所有分支的所有对象ID来猜测HEAD可能指向的内容。如果 HEAD master ,它更喜欢名为 refs / heads / master code>指向相同的对象ID,然后clone将新库中的默认分支设置为 master



否则,具有匹配OID的第一个分支(当分支以字母数字排序时)将成为默认分支。如果没有分支具有匹配的OID,那么 HEAD 将直接设置为对象ID(即分离的HEAD)。


My understanding is that the default branch of a cloned repository is to be whatever HEAD points to in the repo being cloned.

I now have a case where this is not true. My understanding is obviously flawed, so what does determine the default checkout branch when cloning a (bare) repo?

The last commit on that repo was a merge between the branch referenced in the bare repo's HEAD into the branch I'm getting as the checkout branch in the clone.

Running git remote show origin returns:

Fetch URL: ...
Push  URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
  <bad-branch>
  live
Remote branches:
  ...

Bare repo uses Git version 1.8.2.1, client uses 1.7.12.4, transport is SSH.

Maybe the answer is actually this one here. This answer confirms it. If there is a choice of symbolic refs all pointing to the same revision as HEAD, the client will guess which branch to use.

解决方案

Beginning with Git 1.8.5, the server will send the actual branch name that HEAD points to, in the "symref" capability. If you have both a client and server newer than Git 1.8.5, it will update HEAD correctly.

Prior to that, the client will guess what HEAD may have pointed to by comparing the object ID that HEAD (ultimately) points to with all the object IDs of all the branches. It prefers a branch named refs/heads/master: if both HEAD and master point to the same object ID, then clone will set the default branch in the new repository to master.

Otherwise, the first branch with a matching OID (when the branches are sorted alphanumerically) will be the default branch. If no branches have matching OIDs, then HEAD will be set directly to the object ID (ie, a detached HEAD).

这篇关于什么决定了“git clone”之后的默认分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆