git使用中 error: pathspec ‘XXX‘ did not match any file(s) known to git 报错解决方法

一、报错原因

本人在本地开发中,切换同事新切换的分支时:

git checkout XXX

会报以下错误:

error: pathspec 'XXX' did not match any file(s) known to git

二、解决问题

1、首先看下所有分支 是否有同事的新分支

git branch -a

2、如果没看到,那么执行以下操作,这步是获取所有分支

git fetch

执行完会看到这样提示

remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
Unpacking objects: 100% (4/4), 1.06 KiB | 90.00 KiB/s, done.
From codeup.aliyun.com:5eeb0689892c58bb7c394ab5/pxb/pxb-fronted
 * [new branch]      XXX -> origin/XXX

3、切换到远程同事分支:

git checkout origin/XXX

提示:

Note: switching to 'origin/XXX'.

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 dc877cd XXX

4、现在可以看到自己的分支是一串数字字母,这时新建并切换到同事的分支

git checkout -b XXX

5、现在需要跟远程的同事分支进行关联

git branch -u origin/XXX XXX

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

Already up-to-date.

大功告成~

你可能感兴趣的:(bug解决,git,bug,web)