git clone时,提示warning: remote HEAD refers to nonexistent ref, unable to checkout.

问题描述:

最近做Android开发,采用的是git管理代码,从git服务器上获取Contacts模块的代码:

git clone your-git-server

提示:warning: remote HEAD refers to nonexistent ref, unable to checkout.

并且Contacts模块的代码并没有下载到工作区。


解决方法:

原因是.git目录下.git/refs/heads不存在HEAD指向的文件,这个时候可以用git show-ref命令查看

获得如下打印:

5fa0b60252ca2c10fa3c2e12780d351c047c802d refs/remotes/origin/branch_qc_origin
5fa0b60252ca2c10fa3c2e12780d351c047c802d refs/tags/XXXXXXXXXXXX
48dee3a5f7b9cac98349e949275c652e02b0b67e refs/tags/PXXXXV0.0.0B01-bringup
505a9bb0c6d815e6db561f7cb7ed0e20cd73ddde refs/tags/PXXXX_02550_201309260427
e2b211a3c9d8dabec9fe1018b4f7db5c953832ea refs/tags/PXXXX_bsp_02550_201309260422
0848e8b7922c78dbb364aa0e7c1b8375d16a70a3 refs/tags/branch_PXXXX_02550_201309190102
7384803be7c8866393b96ebaaa7e1b2b119654e7 refs/tags/branch_PXXXX_02550_201309200102
480f444dd26bb238aeaacf15da748ad861ea9378 refs/tags/branch_PXXXX_02550_201309210102

......

可以看出,全部是标签tag,并没有类似refs/head/branch_name

继续执行命令: 

git branch  //输入出空

git branch -a //输出 remotes/origin/branch_qc_origin

git checkout remotes/origin/branch_qc_origin // checkout的是git branch -a输出的内容

这样通过ll命令查看,Contacts代码下载到工作目录了

接着创建分支:git checkout -b remotes/origin/branch_qc_origin

git branch //可以看到输出*remotes/origin/branch_qc_origin了,不再为空

git branch -m remotes/origin/branch_qc_origin master  //重命名分支叫master

git show-ref命令查看也能看到head了

至此,问题得到解决。




  • 13
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值