两者之间有什么区别?git pullgit fetch?


当前回答

git-pull - Fetch from and merge with another repository or a local branch
SYNOPSIS

git pull   …
DESCRIPTION

Runs git-fetch with the given parameters, and calls git-merge to merge the 
retrieved head(s) into the current branch. With --rebase, calls git-rebase 
instead of git-merge.

Note that you can use . (current directory) as the <repository> to pull 
from the local repository — this is useful when merging local branches 
into the current branch.

Also note that options meant for git-pull itself and underlying git-merge 
must be given before the options meant for git-fetch.

如果你想要合并历史,你会拉拉, 你会拉拉,你会拉拉拉,如果你只是"想要的cotz" ,因为有人一直在标记 一些文章在这里。

其他回答

Git允许在较新的承诺之后适用按时间顺序排列的旧承诺。 因此,存放库之间转移承诺的行为分为两步:

  1. 正在从远程分支复制新承诺, 复制本地副本中的此远程分支 。

    (收回业务)master@remote >> remote/origin/master@local

  2. 整合对地方分支机构的新承诺

    (内购外业务)remote/origin/master@local >> master@local

第二步有两种方法,你可以:

  1. 在上一个共同祖先之后,将本地分支叉到叉口,并添加与本地仓库独特的承诺平行的新承诺,通过合并承诺最终完成,关闭叉口。
  2. 在上一个共同祖先后插入新承诺,并重新应用本地仓库独有的承诺。

git术语术语,第1步是git fetch,第2步是git mergegit rebase

git pullgit fetchgit merge

您可以从远程仓库获取, 查看差异, 然后拉动或合并 。

这是被称作远程仓库的示例origin和支派,和支派,master跟踪远程分支origin/master:

git checkout master                                                  
git fetch                                        
git diff origin/master
git rebase origin master

Git使用两个命令从远程到本地获取最新版本的分支 :

  1. git 获取: Git 将会从远程获取最新版本到本地版本, 但不会自动合并 。git fetch origin master git log -p master..origin/master git merge origin/master

    以上命令意味着从远程到源主分支下载主分支的最新版本。 然后比较本地主分支和源主分支。 最后, 合并 。

  2. Git将从远程获取最新版本, 并合并到本地 。

        git pull origin master

    以上命令相当于git fetchgit merge在实践中,git fetch也许更安全,因为在合并之前,我们可以看到变化,决定是否合并。

实际上 Git 保有一份您自己的代码副本和远程仓库 。

命令git fetch通过从远程仓库获取数据来更新您的本地副本。 我们需要这个数据的原因是, 其他人可能对代码做了一些修改, 您想要不断更新自己 。

命令git pull将远程仓库的更改引入到您保存自己的代码的位置。通常,git pull这样做的方式是先做一个“ 直接获取” , 将远程仓库的本地副本更新, 然后将修改合并到您自己的代码存储处, 并有可能将您的工作副本合并到您自己的代码存储处 。

简简单简的答案是:git pull简单git fetch和继 继 继 继 继 继git merge.

必须指出,git pull不管你喜不喜欢自动合并。这当然可能导致合并冲突。让我们假设你的远程是origin并且你的分支是master。如果您git diff origin/master在拉车之前,你应该对潜在的合并冲突有某种了解,并且可以据此为你的当地部门做好准备。

除了拉和推,一些工作流程涉及git rebase,例如这一条,我从相关条款中转述如下:

git pull origin master
git checkout foo-branch
git rebase master
git push origin foo-branch

如果你发现自己处于这种情况, 你可能会被诱惑git pull --rebase除非您真的知道自己在做什么 否则我建议不要这么做man页面git-pull版本, 版本2.3.5:

这是一个潜在危险的操作模式。 它重写历史, 当您已经发布历史时, 历史并不是好兆头。 除非您仔细阅读了 git- rebase(1) , 否则不要使用此选项 。