git 为什么我不能从我的远程分支拉?

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

Why can't I pull from my remote branch?

gitbranchgit-rebasegit-pull

提问by Grammin

[console]: git remote -v
origin [email protected]:myProj/myProj.git(fetch)
origin [email protected]:myProj/myProj.git(push)

[console]: git branch -a
*myBranch
development
remotes/origin/myBranch
remotes/origin/development

[console]: git pull origin/myBranch myBranch
fatal: 'origin/myBranch' does not appear to be a git repository
fatal: Could not read from remote repository

I originally made this branch and have been pushing to it for a while. Although yesterday I did rebase from another branch into my branch so maybe that messed something up?

我最初制作了这个分支,并且已经推动了一段时间。虽然昨天我确实从另一个分支变基到了我的分支,所以也许这搞砸了?

回答by torek

You have the syntax wrong: it's git pull [ remote[ branch-name] ], not git pull remote/branch-namebranch-name. In this case you would need git pull origin myBranch.

您的语法错误:它是,不是。在这种情况下,您需要.git pull [ remote[ branch-name] ]git pull remote/branch-namebranch-namegit pull origin myBranch

That said, I recommend notusing git pullat all, at least not until you are very familiar with Git. The reason is that git pulldoes two things, and the second thing it does is run git merge, which:

也就是说,我建议完全不要使用git pull,至少在您非常熟悉 Git 之前不要使用。原因是它git pull做了两件事,它做的第二件事是 run git merge,它:

  • can fail to happen automatically, stop in the middle, and need help from you;
  • produces "foxtrot merges", which are sort of backwards, whenever it makes a real merge;
  • is usually better done as git rebaseanyway.
  • 可能会自动失败,中途停止,需要您的帮助;
  • 产生"foxtrot merges",这是一种倒退,每当它进行真正的合并时;
  • 通常最好这样做git rebase

The first half of git pullis git fetch, so you can just run git fetchand then, after it succeeds, run either git mergeor git rebaseas desired. Both of these commands take much more sensible arguments than git pull.

的前半部分git pullgit fetch,因此您可以直接运行git fetch,然后在成功后运行git mergegit rebase根据需要运行。这两个命令都比git pull.

With git fetch, you name the remote to fetch from, e.g., git fetch origin(or just let git fetchfigure it out: git fetchwith no arguments will generally figure out to use originautomatically).

使用git fetch,您可以命名要从中获取的遥控器,例如,git fetch origin(或者只是git fetch弄清楚:git fetch没有参数通常会origin自动计算出使用)。

With both git mergeand git rebase, you name the origin/myBranchremote-tracking branch, or just let Git figure it out, again.

使用git mergegit rebase,您可以命名origin/myBranch远程跟踪分支,或者让 Git 再次弄清楚。

All that also said, git pullwill usually figure all of these out on its own as well. In particular if git mergeor git rebasecan figure out to use origin/myBranch, git pullcan figure out to use originand origin/myBranchfor its two steps.

所有这些也说,git pull通常也会自己解决所有这些问题。尤其是如果git mergegit rebase能算出使用origin/myBranchgit pull能算出使用originorigin/myBranch为其两个步骤。

回答by Flows

The correct syntax is git pull origin myBranchThe first argument of the command should be the name of the remote, as suggested by the error fatal: 'origin/myBranch' does not appear to be a git repository

正确的语法是git pull origin myBranch命令的第一个参数应该是远程的名称,如错误所建议的fatal: 'origin/myBranch' does not appear to be a git repository