错误:pathspec'test-branch'与git已知的任何文件都不匹配 [英] error: pathspec 'test-branch' did not match any file(s) known to git

查看:2672
本文介绍了错误:pathspec'test-branch'与git已知的任何文件都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Git的新用户。我已经创建了一个名为Spoon-Knife的仓库(可用于练习与Git分叉)。然后,我通过运行本地克隆它

$ g $克隆https://github.com/rohinichoudhary/Spoon-Knife.git

该存储库包含三个分支,即


  • master

  • test-branch

  • 更改标题



运行 git branch 时,它只显示 * master ,而不是其余的两个分支。当我运行

  git checkout test-branch 

我得到以下错误:


错误:pathspec'test-branch'没有匹配git已知的任何文件。


为什么会发生这种情况?如何解决这个问题?

解决方案


当我运行 git分支,它只显示 * master ,而不是其余的两个分支。


git branch 不会列出 test_branch ,因为您的本地回购中不存在这样的本地分支,但是。克隆回购时,不管在远程回购中存在的分支数量是多少,都会在结果克隆中创建并检出一个本地分支( master ,here))你从克隆。在这个阶段, test_branch 只存在于你的仓库中作为 远程跟踪分支,而不是本地分支。


而当我运行时

  git checkout test-branch 

我收到以下错误[...]

您必须使用Git的旧版本。在更新的版本中(从v1.7.0-rc0开始),


如果找不到< branch> ,但
中存在跟踪分支正好有一个远程服务器(称之为< remote> )和一个匹配的名称,treat [ git checkout< branch> ]作为
相当于

  $ git checkout -b< branch> --track< remote> /< branch> 


只需运行

  git checkout -b test_branch --track origin / test_branch 

代替。或者更新到更新版本的Git。


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 clone https://github.com/rohinichoudhary/Spoon-Knife.git

This repository contains three branches, i.e.

  • 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 checkout test-branch

I get the following error:

error: pathspec 'test-branch' did not match any file(s) known to git.

Why is this happening? How can I solve this problem?

解决方案

When I run git branch, it only shows *master, not the remaining two branches.

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-tracking branch, not as a local branch.

And when I run

git checkout test-branch

I get the following error [...]

You must be using an "old" version of Git. In more recent versions (from v1.7.0-rc0 onwards),

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>

Simply run

git checkout -b test_branch --track origin/test_branch

instead. Or update to a more recent version of Git.

这篇关于错误:pathspec'test-branch'与git已知的任何文件都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆