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


当前回答

简简单简的答案是: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) , 否则不要使用此选项 。

其他回答

其中一个使用实例git fetch是,以下将告诉您自您上次拉动以来远程分支的任何变化... 这样您就可以在实际拉动之前检查, 这样就可以改变您当前分支和工作副本中的文件 。

git fetch
git diff ...origin

见见git diff双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双- 双..三点和三点...语法。

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

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

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

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

                                         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-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 获取

帮助您从一个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