为什么 git 不能将“origin/master”识别为有效的对象名称?

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

Why does git not recognize "origin/master" as a valid object name?

git

提问by Rose Perrone

~/www> git branch --track live origin/master
fatal: Not a valid object name: 'origin/master'.
~/www> git remote
origin
~/www> git branch
* master
  test_branch
  working_branch

I also tried creating a tracking branch with:

我还尝试使用以下方法创建跟踪分支:

git branch live
git branch --set-upstream live origin/master

but I got the same error

但我遇到了同样的错误

采纳答案by Steven Penny

$ git branch -r
  origin/1.x
  origin/1.x@60
  origin/1.x@63
  origin/HEAD -> origin/master
  origin/master

$ git branch --track live origin/blah
fatal: Not a valid object name: 'origin/blah'.

As has been suggested you can only track a remote if it has been added. Perhaps add the remote like this

正如所建议的那样,您只能跟踪已添加的遥控器。也许像这样添加遥控器

$ git remote add upstream git://github.com/svnpenn/rtmpdump.git

$ git fetch upstream

Example

例子

回答by TachyonVortex

Your output from git remoteconfirms that you've successfully added your originremote.

您的输出git remote确认您已成功添加origin遥控器。

I expect the problem is that you haven't yet created the remote-tracking branch(es). If you do git branch -r, it probably won't output anything. So origin/masteris not a valid object name because that remote-tracking branch doesn't exist yet.

我预计问题是您尚未创建远程跟踪分支。如果你这样做git branch -r,它可能不会输出任何东西。Soorigin/master不是有效的对象名称,因为该远程跟踪分支尚不存在。

The solution is to do git fetch originto create the remote-tracking branch(es). If you then do git branch -r, you'll see origin/masternow exists.

解决方案是git fetch origin创建远程跟踪分支。如果你然后这样做git branch -r,你会看到origin/master现在存在。

回答by Bleeding Fingers

I was encountering the very same problem. And it turned out that I didn't have write permission in the remote. And hence the error.

我遇到了同样的问题。结果我在遥控器上没有写权限。因此错误。

Make sure you have the write permissions at remote. Not have one is one of the causes of this particular error.

确保您具有远程写入权限。没有一个是导致此特定错误的原因之一。