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

一 問題概述

今天在工做中遇到一個問題,使用好久的一個local git repository,裏面只有develop分支,那麼如今想將分支切換到master分支,問題來了,在切換到master分支時:git

  1. git checkout master

提示以下錯誤:composer

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

二 問題解決

1.首先咱們看一下分支狀況:fetch

  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.若是沒有看到你想要的分支,先獲取全部分支:this

  1. git fetch

3.切換到遠程master分支:spa

  1. git checkout origin/master

 

提示以下:orm

  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,效果以下:ci

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

 

5.如今咱們能夠從當前的detached分支切換並新建分支,能夠理解爲即將新建立的分支是由當前detached 分支出來的(爲了爲後續作準備,此處新分支就叫作master):rem

  1. git checkout -b master

 

5.這時咱們使用git pull會提示以下錯誤:it

  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指定遠程的分支和本地的分支來進行更新,但此處咱們使用提示中的第二種方式,創建本地分支和遠程分支的追蹤關係:io

  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!

相關文章
相關標籤/搜索