当前位置:   article > 正文

git常见问题记录:【git clone后报错】 warning: remote HEAD refers to nonexistent ref, unable to checkout.

warning: remote head refers to nonexistent ref, unable to checkout.


1、概述

比如我从服务器上获取 DPDK 的代码:

git clone 【地址】
  • 1

在这里插入图片描述
发现看似代码下载下来了,但是 ls 命令后项目文件夹里的内容都是空的!!
可以看到最后有个 warning :warning: remote HEAD refers to nonexistent ref, unable to checkout.

2、原因

git clone 代码时会默认拉取远程服务器 master 主分支下的代码,可是我创建的主分支没有用 master 命名,里面是 origin/20.11 分支,目录下 .git/refs/heads 不存在 HEAD 指向的文件,因此产生了警告。

remotes/m/master -> origin/master //其余工程代码有master分支

上下对比:

remotes/m/master -> origin/20.11 //本工程代码分支没有master分支导致警告

如下图显示:

ls .git/refs/heads/
  • 1

在这里插入图片描述

3、解决方法

1、进入git clone 操作后,生成的项目文件夹内,使用 git branch -a 查看所有的分支

hwc@hwc:~/dpdk$ git branch -a
  remotes/origin/18.11.11
  remotes/origin/19.11.14
  remotes/origin/20.11
  remotes/origin/default
  • 1
  • 2
  • 3
  • 4
  • 5

2、选择自己需要的分支,比如我需要获取 origin/20.11 分支上的代码,那么执行操作git checkout remotes/origin/20.11

hwc@hwc:~/dpdk$ git checkout origin/20.11
Note: checking out 'origin/20.11'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at d2d894a55f Add: supports the "set link-up/link-down" command.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

3、这时候 ls 命令就能看到你想要的代码

hwc@hwc:~/dpdk$ ls
app         devtools  examples     lib          Makefile           mk      test
buildtools  doc       GNUmakefile  license      meson.build        pkg     usertools
config      drivers   kernel       MAINTAINERS  meson_options.txt  README
  • 1
  • 2
  • 3
  • 4

4、新建一个分支后,操作git log, git status等命令。

hwc@hwc:~/dpdk$ git checkout -b dev-20.11
Switched to a new branch 'dev-20.11'
  • 1
  • 2

到此,解决问题!


谢谢点赞关注哈!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/586726
推荐阅读
相关标签
  

闽ICP备14008679号