来自 git 的令人困惑的错误消息

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

Confusing error message from git

gitgithub

提问by cinek

I got this message from Git:

我从 Git 收到这条消息:

You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.

您要求从远程“原点”拉取数据,但未指定分支。因为这不是您当前分支的默认配置远程,所以您必须在命令行上指定一个分支。

Can anyone explain it? and more important how to fix it?

谁能解释一下?更重要的是如何修复它?

采纳答案by p4bl0

You have to tell git which branch you want to pull from the "origin" remote repos.

您必须告诉 git 要从“源”远程存储库中提取哪个分支。

I guess you want the default branch (master) so git pull origin mastershould fix your problem.

我猜你想要默认分支(主)所以git pull origin master应该解决你的问题。

See git help branch, git help pulland git help fetchfor more informations.

git help branchgit help pullgit help fetch更多的信息。

回答by Aristotle Pagaltzis

To fix it, assuming you are on the masterbranch and want to pull the masterbranch from the originremote, in new enough Git versions (1.8 or newer):

要修复它,假设您在master分支上并希望masterorigin远程拉取分支,使用足够新的 Git 版本(1.8 或更高版本):

git branch -u origin/master master

(Analogously for other branches and/or remotes.)

(类似于其他分支机构和/或遥控器。)

If you can combine this with a push, it's even shorter:

如果您可以将其与推送结合使用,则它会更短:

git push -u origin master

Thereafter, a plain git pull/git pushwill do what you expect.

此后,一个普通的git pull/git push会做你所期望的。



During the Git 1.7 series, git branchdidn't have the -uswitch (only git pushdid), and instead you had to use the much longer --set-upstream:

在 Git 1.7 系列期间,git branch没有-u开关(只有git push),相反,您必须使用更长的时间--set-upstream

git branch --set-upstream master origin/master

Note the reversal of arguments compared to -u. I fumbled this order more than once.

请注意与-u. 我不止一次地摸索了这个命令。



All of these, by the way, are shorthands for doing the following, which you can still do explicitly:

顺便说一下,所有这些都是执行以下操作的简写,您仍然可以明确地执行这些操作:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Before 1.7, you hadto do it this way.

在 1.7 之前,您必须这样做。

回答by Tomek Szpakowicz

Message says exactly what it is about. Your current branch is not associated with (is not tracking) any branch in origin. So git doesn't know what to pull.

消息准确地说明了它的内容。您当前的分支未与origin 中的任何分支关联(未跟踪)。所以git不知道要拉什么。

What to do? That depends...

该怎么办?那要看...

In most usual situation you are working off some local branch xyzwhich branched from masterwhich is cloned from origin's master. The usual way to resolve it is to switch to masterand pull to synchronize it with originand then come back to xyzand rebase master.

在大多数情况下,您正在处理一些本地分支xyz,该分支从master分支,而master分支是从origin的 master克隆的。解决它的通常方法是切换到master和 pull 以将其与origin同步,然后返回xyzrebase master.

But in your situation you might want to do something else. We can't know it without knowing details of your branches and remotes and how you intent to use them.

但在您的情况下,您可能想做其他事情。如果不了解您的分支机构和遥控器的详细信息以及您打算如何使用它们,我们就无法知道。