为什么“git pull”从存储库中获取所有分支而“git pull origin master”却没有?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17479630/
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
Why does "git pull" get all branches from repository but "git pull origin master" doesn't?
提问by Prostak
Why does git pull
get all branches from repository but git pull origin master
doesn't? I discovered it the hard way. Is it the only functional difference between these two commands?
为什么git pull
从存储库中获取所有分支但git pull origin master
没有?我是通过艰难的方式发现的。这是这两个命令之间唯一的功能区别吗?
Explanation like this tells me nothing:
像这样的解释什么也没告诉我:
git pull
= git fetch origin
+ git merge origin/master
git pull
= git fetch origin
+git merge origin/master
git pull origin master
= git fetch origin master
+ git merge FETCH_HEAD
git pull origin master
= git fetch origin master
+git merge FETCH_HEAD
回答by esycat
The latter command, git pull origin master
, tells git to fetch and merge specifically the master
branch (from the remote named origin
, to be even more precise).
后一个命令,git pull origin master
告诉 git 获取和合并特定的master
分支(从远程 named origin
,更准确地说)。
git pull
fetches updates for all local branches, which track remote branches, and then merges the current branch.
git pull
获取所有本地分支的更新,跟踪远程分支,然后合并当前分支。
回答by phihag
From the documentation of git pull
:
git pull
runsgit fetch
with the given parameters and calls git merge to merge the retrieved branch heads into the current branch
git pull
git fetch
使用给定的参数运行并调用 git merge 将检索到的分支头合并到当前分支中
When you call git fetch
without arguments, the following happens
当您git fetch
不带参数调用时,会发生以下情况
Fetches named heads or tags from one or more other repositories, along with the objects necessary to complete them.
git fetch
[fetches] from (...) a single named repository (...)
从一个或多个其他存储库中获取命名的头部或标签,以及完成它们所需的对象。
git fetch
[fetches] from (...) 单个命名存储库 (...)
When you add arguments, only the specified remote and head (=branch/tag/commit/...) are fetched, and then merged.
添加参数时,仅获取指定的远程和头 (=branch/tag/commit/...),然后合并。