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


当前回答

简单解释:

git fetch

获取元数据。 如果您想要检查最近创建的分支, 您可能需要在退出前进行获取 。

git pull

从远程获取元元数据,并将文件从远程移动并合并到分支

其他回答

我也为此挣扎过。事实上,我来到这里时,用谷歌搜索了完全相同的问题。阅读了所有这些答案,终于在我脑海中画出了一张图片,我决定试着从下面看2个储存库和1个沙箱的状况,以及一段时间以来在看它们的版本时所采取的行动。这就是我所想出来的。如果我在任何地方搞砸了,请纠正我。

三个邮箱有一个接听器:

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - fetch               -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     -                     -
- @ R01             -     - @ R01+              -     - @R01+               -
---------------------     -----------------------     -----------------------

三号邮局拉一拉一拉

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - pull                -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     - merged with R02     -
- @ R01             -     - @ R01+              -     - @R02+               -
---------------------     -----------------------     -----------------------

这帮助我理解了为什么买东西很重要。

git fetch将检索远程分支,以便您能够git diffgit merge它们与当前分支一起存在。git pull将运行当前分支所跟踪的远程条格获取,然后合并结果。您可以使用git 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 获取

帮助您从一个git repository。让我们假设你在一个团队中工作 使用GitFlow,其中团队在多个branches(特征). 与git fetch --all command您可以了解所有新的信息branchesrepository.

大部分git fetch用于git reset。例如,您想要将全部本地更改恢复到当前仓库状态。

git fetch --all // get known about latest updates
git reset --hard origin/[branch] // revert to current branch state

Git 拉着

此命令更新您branch与当前repository branch状态。让我们继续GitFlow多个特性branches原为mergeddevelop分支,当您想要为项目开发新特性时,您必须去开发branch并做一个git pull以获得当前状态develop branch

GitFlow 文档文档https://gist.github.com/peterdeweese/4251497