错误:pathspec 'test-branch' 与 git 已知的任何文件都不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30800454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: pathspec 'test-branch' did not match any file(s) known to git
提问by Rohini Choudhary
I am a new user of Git. I have forked a repository called Spoon-Knife (available for practicing forking with Git). Then, I cloned it locally by running
我是 Git 的新用户。我已经分叉了一个名为 Spoon-Knife 的存储库(可用于练习使用 Git 分叉)。然后,我通过运行在本地克隆它
git clone https://github.com/rohinichoudhary/Spoon-Knife.git
This repository contains three branches, i.e.
这个存储库包含三个分支,即
master
,test-branch
,change-the-title
.
master
,test-branch
,change-the-title
.
When I run git branch
, it only shows *master
, not the remaining two branches. And when I run
当我运行时git branch
,它只显示*master
,而不显示其余的两个分支。当我跑
git checkout test-branch
I get the following error:
我收到以下错误:
error: pathspec 'test-branch' did not match any file(s) known to git.
错误:pathspec 'test-branch' 与 git 已知的任何文件都不匹配。
Why is this happening? How can I solve this problem?
为什么会这样?我怎么解决这个问题?
采纳答案by jub0bs
When I run
git branch
, it only shows*master
, not the remaining two branches.
当我运行时
git branch
,它只显示*master
,而不显示其余的两个分支。
git branch
doesn't list test_branch
, because no such local branch exist in your local repo, yet. When cloning a repo, only one local branch (master
, here) is created and checked out in the resulting clone, irrespective of the number of branches that exist in the remote repo that you cloned from. At this stage, test_branch
only exist in your repo as a remote-trackingbranch, not as a localbranch.
git branch
未列出test_branch
,因为您的本地存储库中尚不存在此类本地分支。克隆一个 repo 时,只会master
在生成的克隆中创建和检出一个本地分支(此处),而不管您从中克隆的远程 repo 中存在的分支数量如何。在此阶段,test_branch
仅作为远程跟踪分支存在于您的 repo 中,而不是作为本地分支存在。
And when I run
git checkout test-branch
I get the following error [...]
当我跑
git checkout test-branch
我收到以下错误 [...]
You must be using an "old" version of Git. In more recent versions (from v1.7.0-rc0 onwards),
您必须使用“旧”版本的 Git。在更新的版本中(从 v1.7.0-rc0 开始),
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat [git checkout <branch>
] as equivalent to$ git checkout -b <branch> --track <remote>/<branch>
如果
<branch>
未找到但确实存在一个<remote>
具有匹配名称的远程(称为)的跟踪分支,则将[git checkout <branch>
] 视为等效于$ git checkout -b <branch> --track <remote>/<branch>
Simply run
只需运行
git checkout -b test_branch --track origin/test_branch
instead. Or update to a more recent version of Git.
反而。或者更新到更新版本的 Git。
回答by kenorb
The modern Git should able to detect remote branches and create a local one on checkout.
现代 Git 应该能够检测远程分支并在结账时创建一个本地分支。
However if you did a shallow clone(e.g. with --depth 1
), try the following commands to correct it:
但是,如果您进行了浅层克隆(例如使用--depth 1
),请尝试以下命令来纠正它:
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --all
and try to checkout out the branch again.
并尝试再次结帐分支。
Alternatively try to unshallow your clone, e.g. git fetch --unshallow
and try again.
或者尝试取消您的克隆,例如git fetch --unshallow
,再试一次。
See also: How to fetch all remote branches?
另请参阅:如何获取所有远程分支?
回答by NIKHIL CHAURASIA
My friend, you need to create those corresponding branches locally first, in order to check-out to those other two branches, using this line of code
朋友,你需要先在本地创建那些对应的分支,才能结账到另外两个分支,使用这行代码
git branch test-branch
and
和
git branch change-the-title
git branch change-the-title
then only you will be able to do git checkoutto those branches
那么只有你才能对这些分支进行git checkout
Also after creating each branch, take latest changes of those particular branches by using git pull origin branch_nameas shown in below code
同样在创建每个分支后,使用git pull origin branch_name 获取这些特定分支的最新更改, 如下面的代码所示
git branch test-branch
git checkout test-branch
git pull origin test-branch
and for other branch named change-the-titlerun following code =>
对于其他名为change-the-title 的分支,请 运行以下代码 =>
git branch change-the-title
git checkout change-the-title
git pull origin change-the-title
Happy programming :)
快乐编程:)
回答by pilkch
You can also get this error with any version of git if the remote branch was created after your last clone/fetch and your local repo doesn't know about it yet. I solved it by doing a git fetch
first which "tells" your local repo about all the remote branches.
如果远程分支是在您最后一次克隆/获取之后创建的,并且您的本地存储库还不知道它,您也可以使用任何版本的 git 收到此错误。我通过git fetch
首先“告诉”您的本地存储库有关所有远程分支来解决它。
git fetch
git checkout test-branch
回答by Shajid
just follow three steps, git branch problem will be solved.
只需三步,git分支问题就解决了。
git remote update
git fetch
git checkout --track origin/test-branch
git remote update
git fetch
git checkout --track origin/test-branch
回答by Bruno Kocziceski
Solution:
解决方案:
To fix it you need to fetch first
要修复它,您需要先获取
$ git fetch origin
$ git rebase origin/master
Current branch master is up to date.
当前分支 master 是最新的。
$ git checkout develop
Branch develop set up to track remote branch develop from origin.
分支开发设置为从源跟踪远程分支开发。
Switched to a new branch ‘develop'
切换到一个新的分支 'develop'
回答by Yash Varshney
This error can also appear if your git branch is not correct even though case sensitive wise. In my case I was getting this error as actual branch name was "CORE-something" but I was taking pull like "core-something".
如果您的 git 分支不正确,即使区分大小写,也会出现此错误。在我的情况下,我收到此错误,因为实际分支名称是“CORE-something”,但我像“core-something”一样拉动。
回答by Axel Bregnsbo
I got this error because the instruction on the Web was
我收到这个错误是因为网上的说明是
git checkout https://github.com/veripool/verilog-mode
git checkout https://github.com/veripool/verilog-mode
which I did in a directory where (on my own initiative) i had run git init
.
The correct Web instruction (for newbies like me) should have been
我在一个目录中做的(我自己主动)运行了git init
. 正确的 Web 说明(对于像我这样的新手)应该是
git clone https://github.com/veripool/verilog-mode
git clone https://github.com/veripool/verilog-mode
回答by Luthoz
Try cloning before doing the checkout.
在结帐前尝试克隆。
do git clone "whee to find it" then after cloning check out the branch
做 git clone "whee to find it" 然后在克隆后检查分支