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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Helm从入门到实践

    Helm从入门到实践

    2021年6月1日
    95
  • decode encode区别_python decode和encode

    decode encode区别_python decode和encode#-*-coding:utf-8importsys”’*首先要搞清楚,字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode(‘gb231…

    2022年10月7日
    6
  • jedis和jediscluster_jedis连接redis集群

    jedis和jediscluster_jedis连接redis集群packagecom.redis;importorg.junit.Test;importredis.clients.jedis.HostAndPort;importredis.clients.jedis.JedisCluster;importredis.clients.jedis.JedisPoolConfig;importredis.clients.jedis.SortingPara…

    2022年10月9日
    4
  • oracle创建索引和删除索引

    oracle创建索引和删除索引创建CREATEINDEXindex_Trans_list(索引名)ONTrans_list(表名) (receivedepid(字段名))删除dropindexindex_Trans_list(索引名)

    2025年9月14日
    11
  • ubuntu设置远程桌面_ubuntu安装虚拟显示器

    ubuntu设置远程桌面_ubuntu安装虚拟显示器IP变化的所以用向日葵连接,设置开机自动启动如果ubuntu还没有安装桌面那么先安装桌面在安装过程中选择lightdm,如图所示:如果本来就有图形桌面那么需要安装虚拟显示器因为如果将HDMI或者其他与物理显示器相连的线拔掉,即想节省一块显示器,那么就会发现,向日葵虽然可以远程连接到桌面,但是却控制不了,因此需要虚拟显示器。确保ssh可以远程连接后再往下进行。安装虚拟桌面:然后配置虚拟显示器,创建这个文件【/usr/share/X11/xorg.conf.d/xorg.conf】内容如下:

    2022年8月21日
    5
  • java 日志查看_Java日志

    日志对于一个系统来说非常重要,查找异常信息、分析系统运行情况等都需要用到日志。所以无论是JDK还是第三方都提供了关于日志的相关工具,本文分别介绍以下几种工具,以及各种工具间的整合、原理。JDK的java.util.logging包第三方日志工具(commons-logging/slf4j,log4j/logback)JDK的java.util.logging包JDK1.4引入了java.util….

    2022年4月6日
    85

发表回复

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

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