admin管理员组

文章数量:1650764

问题场景:我在远程仓库创建一个分支feature-test,此时本地不存在这个分支:feature-test

① 切换到 feature-test 分支,报错 error: pathspec ‘feature-test’ did not match any file(s) known to git

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-1)
$ git checkout feature-test
error: pathspec 'feature-test' did not match any file(s) known to git

② 查看本地所有的分支,发现本地没有 feature-test 分支

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-1)
$ git branch -a
* feature-1
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature-1
  remotes/origin/master

③ fetch仓库中所有分支:出现 feature-test -> origin/feature-test

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-1)
$ git fetch
From https://gitee/chahuaxiaozhan/company_member
 * [new branch]      feature-test -> origin/feature-test

④ 切换到远程 origin/feature-test 分支,出现如下提示信息:

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-1)
$ git checkout origin/feature-test
Note: switching to 'origin/feature-test'.

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 switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at cf6097d [ADD]测试提交一

⑤ 新建并切换到分支 feature-test :

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member ((cf6097d...))
$ git checkout -b feature-test
Switched to a new branch 'feature-test'

⑥ 将分支 feature-test 和远程分支 origin/feature-test 进行关联:

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-test)
$ git branch -u origin/feature-test feature-test
Branch 'feature-test' set up to track remote branch 'feature-test' from 'origin'.

⑦ 执行 git pull 拉取远程分支代码:

User@6-cpgh0012 MINGW64 /d/mycode/company_frame/company_member (feature-test)
$ git pull
Already up to date.

本文标签: 报错pathspecErrorGitfeature