码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-05-25 00:22:46      阅读:720      评论:0      收藏:0      [点我收藏+]

标签:name   不能   lease   err   into   you   composer   wan   change   

一 问题概述

今天在工作中遇到一个问题,使用很久的一个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.  
  3. You are in ‘detached HEAD‘ state. You can look around, make experimental
  4. changes and commit them, and you can discard any commits you make in this
  5. state without impacting any branches by performing another checkout.
  6.  
  7. If you want to create a new branch to retain commits you create, you may
  8. do so (now or later) by using -with the checkout command again. Example:
  9.  
  10.   git checkout -b new_branch_name
  11.  
  12. 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.  
  5.     git pull <remote> <branch>
  6.  
  7. If you wish to set tracking information for this branch you can do so with:
  8.  
  9.     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.  
  4. and so forth!

 

Bye!

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

标签:name   不能   lease   err   into   you   composer   wan   change   

原文地址:https://www.cnblogs.com/yangcx666/p/9085816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!