当前位置: 代码网 > it编程>编程语言>其他编程 > git常见问题记录:【git clone后报错】 warning: remote HEAD refers to nonexistent ref, unable to checkout.

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

2024年08月03日 其他编程 我要评论
git clone 【地址】发现看似代码下载下来了,但是ls命令后项目文件夹里的内容都是空的!!可以看到最后有个warning。


1、概述

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

git clone 【地址】

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

2、原因

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

上下对比:

如下图显示:

ls .git/refs/heads/

在这里插入图片描述

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

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.

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

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

hwc@hwc:~/dpdk$ git checkout -b dev-20.11
switched to a new branch 'dev-20.11'

到此,解决问题!


谢谢点赞关注哈!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com