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


当前回答

我想用视觉来描述这些事情。也许其他开发商也想看,所以我还要补充一下。我不完全确定这一切是否都正确,所以如果你发现任何错误,请评论。

                                         LOCAL SYSTEM
                  . =====================================================    
================= . =================  ===================  =============
REMOTE REPOSITORY . REMOTE REPOSITORY  LOCAL REPOSITORY     WORKING COPY
(ORIGIN)          . (CACHED)           
for example,      . mirror of the      
a github repo.    . remote repo
Can also be       .
multiple repo's   .
                  .
                  .
FETCH  *------------------>*
Your local cache of the remote is updated with the origin (or multiple
external sources, that is git's distributed nature)
                  .
PULL   *-------------------------------------------------------->*
changes are merged directly into your local copy. when conflicts occur, 
you are asked for decisions.
                  .
COMMIT            .                             *<---------------*
When coming from, for example, subversion, you might think that a commit
will update the origin. In git, a commit is only done to your local repo.
                  .
PUSH   *<---------------------------------------*
Synchronizes your changes back into the origin.

拥有远程镜像的一些主要优点是:

  • 业绩 业绩业绩 业绩业绩(在不试图通过网络挤压所有承诺和信息的情况下标注所有承诺和信息)
  • 反馈反馈反馈反馈反馈有关您所在的本地回收站的状况( 例如, 我使用阿特拉斯斯的源树树, 这将给我一个灯泡, 显示我是否承诺提前或落后于来源 。 这个信息可以用 GIT Fitch 来更新 ) 。

其他回答

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

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 pull获取承诺后尝试自动合并 。上下文敏感,因此所有被拉动的承诺都将合并为您目前活跃的分支。git pull自动合并承诺未经审查,而不先审查。。如果你不仔细管理自己的分支,你可能会遇到频繁的冲突。

  • git fetch收集当前分支中不存在的目标分支的任何承诺,并将其存储在本地仓库中然而,它不会与您当前分支合并。如果您需要不断更新您的仓库,但正在研究一些更新文件时可能中断的文件。要将承诺整合到当前分支中,您必须使用git merge之后。

最简单的说,git pull是否为 a 的git fetch续 续 agit merge.


git fetch更新您的远程跟踪分支refs/remotes/<remote>/。此操作可以随时安全运行,因为它不会改变您在refs/heads.

git pull本地分支提供其远程版本的最新信息,同时更新其他远程跟踪分支。

调自 Git 文档git pull:

git pull运行中git fetch使用给定参数,然后取决于配置选项或命令行的旗帜,将调用其中之一git rebasegit merge以便各处之间互相调和。


有必要记住,在任何特定机器的Git存储库工作时,存储库载有来自所有远程的所有分支的复制件,以及每个地方分支的复制件,你已经做了一些工作。

你可以看到这个使用git branch -a显示您所在的分支机构,包括master和所有遥控器的分支。

master
feature/my-feature-branch
remotes/origin/master
remotes/origin/my-feature-branch
remotes/another-remote-machine/master
remotes/another-remote-machine/my-feature-branch

上面我已指出 遥控遥控器的存在origin以另一个名称返回和另一个远程another-remote-machine.

注意 您不必在所有仓库中拥有每个分支的复制件 。 (remotes 和 local.) 它取决于您通过运行同步 。git pull, git push, git fetch,来自不同的机器 / 仓库 所涉及的。

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

要理解这一点,你首先需要明白,你所在的本地数据库不仅维护着您的本地存储库,而且还维护着远程存储库的本地副本。

git fetch将远程仓库的本地副本更新到最新 。 例如, 如果您的远程仓库是 GitHub , 您可能想要将远程仓库中所做的任何更改移到您的本地副本 远程仓库。 这将允许您执行比较或合并等操作 。

git pull另一方面,会将远程仓库的更改降低到您保存自己的代码的位置。 通常,git pull会做一个git fetch首先将远程存储库的本地副本更新, 然后它将把修改合并到您自己的代码存储库中, 并可能合并到您的工作副本中 。