无法结帐远程 git 分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30064195/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:58:55  来源:igfitidea点击:

cannot checkout remote git branch

gitgithubbranch

提问by ducin

I'm in a github local clone. Below is the list of branches:

我在 github 本地克隆中。以下是分行名单:

$ git branch -a
* master
  online-demo
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/gh-pages
  remotes/origin/master
  remotes/origin/online-demo
  remotes/pateketrueke/develop
  remotes/pateketrueke/gh-pages
  remotes/pateketrueke/master

When I try to checkout a remote branch, I get an error:

当我尝试签出远程分支时,出现错误:

$ git checkout develop
error: pathspec 'develop' did not match any file(s) known to git.

I can't figure out where does that come from. I guess I've been doing such checkouts for ages. Maybe I'm missing something. Anyway, I did git fetch, git fetch originand git pullbecause I'm running out of ideas and there's still the same error.

我无法弄清楚这是从哪里来的。我想我多年来一直在做这样的结账。也许我错过了一些东西。无论如何,我做了git fetchgit fetch origin而且git pull因为我的想法跑出来,还是有相同的错误。

回答by Sébastien Dawans

You don't have any local branch called develop. When doing git checkout developand no local branches are found, git will understand that you want to make a new local branch called develop, based on a developbranch in a remote repo, if any exists. In your case, you have 2 such branches origin/developand pateketrueke/develop, so there is an ambiguity.

您没有任何名为develop. 当这样做git checkout develop并且没有找到本地分支时,git 会理解您想要创建一个名为 的新本地分支develop,基于develop远程仓库中的分支(如果存在)。在您的情况下,您有 2 个这样的分支origin/developand pateketrueke/develop,因此存在歧义。

You can be more explicit about it by using the following form:

您可以使用以下形式更明确地说明它:

git branch develop origin/develop
git checkout develop

or

或者

git branch develop pateketrueke/develop
git checkout develop

depending on what you want.

取决于你想要什么。



These can be abbreviated as:

这些可以缩写为:

git checkout -b develop origin/develop

or

或者

git checkout -b develop pateketrueke/develop

回答by Asher A

You can try checking out the full SHA commit

您可以尝试查看完整的 SHA 提交