赞
踩
比如我从服务器上获取 DPDK 的代码:
git clone 【地址】
发现看似代码下载下来了,但是 ls
命令后项目文件夹里的内容都是空的!!
可以看到最后有个 warning
:warning: remote HEAD refers to nonexistent ref, unable to checkout.
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、进入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'
到此,解决问题!
谢谢点赞关注哈!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。