Git使用之(pathspec master did not match any file(s) known to git)「建议收藏」

Git使用之(pathspec master did not match any file(s) known to git)

大家好,又见面了,我是全栈君。

一 问题概述
今天在工作中遇到一个问题,使用很久的一个local git repository,里面只有develop分支,那么现在想将分支切换到master分支,问题来了,在切换到master分支时:

git checkout master

提示如下错误:

error: pathspec 'master' did not match any file(s) known to git

二 问题解决
1.首先我们看一下分支情况:

git branch -a
* develop
  remotes/composer/develop
  remotes/composer/feature/194
  remotes/composer/feature/198
  remotes/composer/feature/199
  remotes/composer/feature/200
  remotes/composer/master
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/feature/194
  remotes/origin/feature/198
  remotes/origin/feature/199
  remotes/origin/feature/200
  remotes/origin/master

2.如果没有看到你想要的分支,先获取所有分支:

git fetch

3.切换到远程master分支:

git checkout origin/master

提示如下:

Note: checking out 'origin/master'.

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 4beea49... Merge branch 'develop' into 'master'

执行git branch,效果如下:

* (detached from origin/master)
  develop

5.现在我们可以从当前的detached分支切换并新建分支,可以理解为即将新创建的分支是由当前detached 分支出来的(为了为后续做准备,此处新分支就叫做master):

git checkout -b master

5.这时我们使用git pull会提示如下错误:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> master

说明我们新建立的master分支还不能和远程的master分支建立追踪关系(虽然表面我们看似已经建立了master分支,但git不认为它和远程的master有任何关系),当然,您可以按照上面提示那样,通过git pull指定远程的分支和本地的分支来进行更新,但此处我们使用提示中的第二种方式,建立本地分支和远程分支的追踪关系:

git branch -u origin/master master

6.这时我们执行git pull来看看什么反馈:

Already up-to-date.

总结:其实git的人性化做的非常的完备,有时我们不要惧怕提示,而要从中找到问题的解决方法,并时常利用好:

man git
man git branch

and so forth!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111456.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • centos 安装 使用本地图像文件来安装网络安装「建议收藏」

    centos 安装 使用本地图像文件来安装网络安装

    2022年1月17日
    44
  • 5G nr频段_5g哪个信道信号强

    5G nr频段_5g哪个信道信号强文章目录1.工作频段2.基站信道带宽2.1传输带宽配置2.2最小保护带3.信道安排3.1信道栅格3.2同步栅格参考文献1.工作频段NR工作在两大频率范围(FrequencyRange,FR):FR1和FR2,如下表1-1所示[1]。表1-1.频率范围的定义[1](TS38.104Table5.1-1)FR1和FR2中,又划分了多个不同的工作频段,如下表1-2和下表1-3所示[1]。表中的n代表NR。表1-2.NR在FR1中的工作频段[1](TS38

    2022年10月6日
    4
  • mac phpstrom 激活码【2022最新】「建议收藏」

    (mac phpstrom 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html4KDDGND3CI-eyJsa…

    2022年4月1日
    107
  • SDIO接口_gmac接口是什么意思

    SDIO接口_gmac接口是什么意思文章目录SDIO信号和接口SDIO命令流程SDIO寄存器卡检测卡识别卡常用命令SDIO,全称:SecureDigitalInputandOutput,即安全数字输入输出接口。SDIO卡是在SD内存卡接口的基础上发展起来的接口,SDIO接口兼容以前的SD内存卡,并且可以连接SDIO接口的设备,目前根据SDIO协议的SPEC,SDIO接口支持的设备总类有蓝牙,网卡,电视卡等。支持三种不同…

    2022年10月4日
    4
  • N的阶乘(大数阶乘算法)

    N的阶乘(大数阶乘算法)题目描述输入一个正整数N,输出N的阶乘。输入描述:正整数N(0<=N<=1000)输出描述:输入可能包括多组数据,对于每一组输入数据,输出N的阶乘输入例子:4515输出例子:241201307674368000#include<iostream>#include<cstring>usingnames…

    2022年7月24日
    8
  • 参加微软Ignite大会有感

    参加微软Ignite大会有感

    2021年11月26日
    49

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号