tor*_*rek 32

[编辑,2018年5月:git pull不再是shell脚本,现代Git中有一些细节不同.Pull现在还有递归选项,使其对子模块更有用.这个答案忽略了子模块.]

git pull脚本是一种方便的方法,用于调用git fetch后跟git merge(或,with git pull --rebase,with ,git fetch后跟git rebase).

第一个额外的参数git pull告诉它给fetch操作的哪个远程:

git pull origin
Run Code Online (Sandbox Code Playgroud)

例如,意味着从中获取origin.如果你把它留下来,Git使用当前的分支remote:

$ git branch
* master
$ git config --get branch.master.remote
origin
Run Code Online (Sandbox Code Playgroud)

第二个(以及任何其他)参数git pull告诉它要合并哪个或哪些分支.这些是在远程上找到的分支的名称.例如,假设您创建了一个feature2跟踪origin/feature以下内容的新分支:

$ git checkout -b feature2 origin/feature
Run Code Online (Sandbox Code Playgroud)

如果您现在想要获取origin添加到其feature分支的新提交,但将它们合并到您的本地feature2分支:

$ git pull origin feature
Run Code Online (Sandbox Code Playgroud)

如果省略分支名称,git使用当前分支merge:

$ git config --get branch.feature2.merge
feature
Run Code Online (Sandbox Code Playgroud)

请注意,如果列出多个分支名称,Git将执行"章鱼合并".根据我的经验,这通常会让人第一次感到惊讶:他们认为会在每个分支上运行一系列单独的-s,但事实并非如此.git pull remote br1 br2git fetchgit merge


nit*_*oel 14

git pull origin master 将从原始远程,主分支拉出更改并将它们合并到本地签出分支.

where git pull将从默认远程(原点)从所有跟踪分支获取新提交.您还可以在gitconfig文件中配置默认远程和分支名称.

git branch --set-upstream master origin/master
Run Code Online (Sandbox Code Playgroud)

这会将以下信息添加到您的gitconfig文件中:

[branch "master"]
    remote = origin
    merge = refs/heads/master
Run Code Online (Sandbox Code Playgroud)

现在,只要你说它git pull将从原始主机获取.


pok*_*oke 7

git pull origin master是冗长的形式,它指定远程(origin)和要从(master)拉出的分支。如果未指定,Git将应用文档中说明的默认行为:

人们经常在使用时git pull不给出任何参数。传统上,这相当于说git pull origin。但是,当branch.<name>.remote分支上存在配置时<name>,将使用该值代替原始值。

[…]

为了确定在命令行上没有任何refspec参数的情况下运行命令时要获取的远程分支(并有选择地存储在远程跟踪分支中),请查询配置变量的值remote.<origin>.fetch,如果没有,$GIT_DIR/remotes/<origin>参考文件,并使用其Pull:行。