当从git裸仓库克隆时,什么决定了默认分支 [英] what determines default branch when cloning from git bare repository

查看:125
本文介绍了当从git裸仓库克隆时,什么决定了默认分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用git 1.8.3.1从yum install克隆git bare repo时更改默认分支。我一直认为这样做的方法是更改​​远程仓库HEAD文件中的引用,以及几个所以答案似乎证实了这一点。



但是,我发现远程裸回购中HEAD的价值无效。即使我的远程仓库在HEAD中有这个值:

  ref:refs / heads / secondbranch 

当我克隆时,我仍然默认第一支分支!任何想法发生了什么?这些信息还可以存储在哪里?

解决方案

旧版本的git在获取和克隆时不会发送默认分支。相反,他们发送当前HEAD引用的对象ID以及其他引用的对象ID。如果HEAD的对象ID与另一个引用的对象ID相同,则会将HEAD设置为指向该引用。 (如果没有匹配,你将处于分离HEAD状态。)



消歧逻辑很模糊,但是如果你有多个分支指向同样的承诺。它会喜欢一个名为master的分支,然后它会简单地选择它首先看到的分支。



别笑,我是认真的。

这已在 Git 1.8.4.3 中解决。


I'm trying to change the default branch when cloning from a git bare repo using git 1.8.3.1 from yum install. I had always assumed that the way to do this would be to change the reference inside the HEAD file of the remote repo, and several SO answers seem to confirm this.

However, I'm finding the value of HEAD in the remote bare repo to have no effect. Even though my remote repo has this value in HEAD:

ref: refs/heads/secondbranch

I'm still defaulted to firstbranch branch when I clone! Any ideas what's going on here? Where else might this info be stored?

解决方案

Old versions of git do not send the "default branch" when fetching and cloning. Instead, they send the object ID of the current HEAD reference, as well as the object ID of the other references. If the object ID of HEAD is the same as the object ID of another reference, it will set HEAD to point to that reference. (If there was no match, you will be in a detached HEAD state.)

The disambiguation logic is fuzzy, though, if you have more than one branch pointing to the same commit. It will prefer a branch named master, then it will simply pick the one it saw first.

Stop laughing, I'm serious.

This was fixed in Git 1.8.4.3.

这篇关于当从git裸仓库克隆时,什么决定了默认分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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