一 问题概述

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

  1. git checkout master

提示如下错误:

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

二 问题解决

1.首先我们看一下分支情况:

  1. git branch -a
  1. * develop
  2. remotes/composer/develop
  3. remotes/composer/feature/194
  4. remotes/composer/feature/198
  5. remotes/composer/feature/199
  6. remotes/composer/feature/200
  7. remotes/composer/master
  8. remotes/origin/HEAD -> origin/develop
  9. remotes/origin/develop
  10. remotes/origin/feature/194
  11. remotes/origin/feature/198
  12. remotes/origin/feature/199
  13. remotes/origin/feature/200
  14. remotes/origin/master

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

  1. git fetch

3.切换到远程master分支:

  1. git checkout origin/master

提示如下:

  1. Note: checking out 'origin/master'.
  2. You are in 'detached HEAD' state. You can look around, make experimental
  3. changes and commit them, and you can discard any commits you make in this
  4. state without impacting any branches by performing another checkout.
  5. If you want to create a new branch to retain commits you create, you may
  6. do so (now or later) by using -b with the checkout command again. Example:
  7. git checkout -b new_branch_name
  8. HEAD is now at 4beea49... Merge branch 'develop' into 'master'

执行git branch,效果如下:

  1. * (detached from origin/master)
  2. develop

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

  1. git checkout -b master

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

  1. There is no tracking information for the current branch.
  2. Please specify which branch you want to merge with.
  3. See git-pull(1) for details
  4. git pull <remote> <branch>
  5. If you wish to set tracking information for this branch you can do so with:
  6. git branch --set-upstream-to=<remote>/<branch> master

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

  1. git branch -u origin/master master

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

  1. Already up-to-date.

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

  1. man git
  2. man git branch
  3. and so forth!

Bye!

Git使用之(pathspec master did not match any file(s) known to git)的更多相关文章

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

    问题描述: 在远程服务器上新建裸仓库git  --bare init : git clone裸仓库到本地: 本地新建并切换分支xccdev,git checkout -b xccdev: 从xccde ...

  2. git——创建分支后,切换分支报错(error: pathspec 'master' did not match any file(s) known to git)

    error: pathspec 'master' did not match any file(s) known to git 解决办法: 1.查看分支 git branch -a 2.获取所有分支 ...

  3. git commit 提交不了 error: pathspec 'project'' did not match any file(s) known to git.

    1. 问题--使用git将代码提交到码云,使用到以下命令时: git commit -m 'init project' # 报错 error: pathspec 'project'' did not ...

  4. Error: pathspec '*' did not match any file(s) known to git.

    git切换分支报错 error: pathspec 'develop' did not match any file(s) known to git. 解决办法如下: plumm@MACY-PC MI ...

  5. xxx did not match any file(s) known to git

    切换分支的时候,报了标题这么个错误,error: pathspec ''xxx did not match any file(s) known to git. 看见不能切换分支,我首先 git sta ...

  6. git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git

    项目上有一个分支test,使用git branch -a看不到该远程分支,直接使用命令git checkout test报错如下: error: pathspec 'origin/test' did ...

  7. git 提交 src refspec master does not match any

    git init 产生的目录解释   error: src refspec master does not match any. 引起该错误的原因是,目录中没有文件,空目录是不能提交上去的 error ...

  8. Git:错误:error:src refspec master does not match any

    新建立了一个远程仓库,想着把项目放上去.于是在项目目录上: git init 然后就添加远程库 git remote add origin xxxx.git 然后就想push: git push -u ...

  9. GIT问题,error:src refspec master does not match any

    将本地GIT版本库PUSH到一个GITHUB上一个空的版本库时可能会出现如下错误error:src refspec master does not match any原因: 本地版本库为空, 空目录不 ...

随机推荐

  1. Ruby中方法的设计理念

    Ruby中的方法命名遵从与局部变量相同的规则和约定.这是一种设计理念:方法并不因其自身作为方法而被人关注,而是简单地作为提供值的表达式融入到程序的结构中.

  2. css清除浮动方式总结

    1.通过父元素overflow:hidden,缺点:超出部分隐藏,不推荐使用 <!DOCTYPE html> <html lang="en"> <he ...

  3. 原生Ajax--XmlHttpRequest对象和jQuery.ajax()

    Ajax主要就是使用 [XmlHttpRequest]对象来完成请求的操作,该对象在主流浏览器中均存在(除早起的IE) 1.XmlHttpRequest对象介绍 XmlHttpRequest对象的主要 ...

  4. Django中Model-Form验证

    Django中Model-Form验证 class UserType(models.Model): caption=models.CharField(max_length=32) class User ...

  5. JavaScript||什么是面向对象

    什么是对象&面向对象 对象 是一个整体,对外提供功能.例:一个手机 电脑. 面向对象 使用的时候只关注提供的功能不关注内部的细节. 面向对象有三大特点: 抽象:将问题需求抽象出来 例:一个员工 ...

  6. Python第八章(北理国家精品课 嵩天等)

    程序设计方法 8.1体育竞技分析实例 from random import random def printIntro(): print("这个程序模拟两个选手A和B的某种竞技比赛" ...

  7. java面向对象编程--Josephu问题(丢手帕问题)

    Josephu问题为:设编号为1,2,...n的n个人围坐一圈,约定编号为k(1<=k<=n)的人从1开始报数,数到m的那个人出列,它的下一位又从1开始报数,数到m的那个人又出列,依次类推 ...

  8. Linux 登陆配置读取顺序

    Linux用户在登陆到Linux服务器时,一些登陆的提示欢迎信息,以及特定的环境配置等等都按预先设定好的配置来生效.Linux中的这个shell环境会读取很多不同的配置文件来达成上述目的,同时还有登陆 ...

  9. 【oacle入门】表空间类型

    系统表空间 系统表空间包括SYSTEM和SYSAUX表空间,系统表空间是所有数据库必须且自动创建的,一般存放在Oracle的数据字典表及相应数据. 永久表空间 永久表空间用户保存永久性数据,如系统数据 ...

  10. ubuntu mariadb installation

    sudo apt-get install mariadb-server[sudo] password for wadmin: Reading package lists... DoneBuilding ...