Git pull 和 Git fick 之间有什么区别?


当前回答

我花了一点点时间才明白有什么区别,但这只是一个简单的解释。你的当地主人是个分支。

当您克隆一个仓库时, 您会把整个仓库带回本地主机 。 这意味着在那个时候您有一个源代码/ 源代码/ 源代码指针到 HEAD , 主人指向同一个主目录 。

当您开始工作并承诺将主指针推进到 HEAD + 您的承诺。 但是源指针/主指针仍然指向您克隆时是什么。

因此,区别在于:

如果您做一个 Git 抓取它, 它只会获取远程仓库( GitHub) 的所有更改, 并将来源/ 指针移到 HEAD 。 与此同时, 您的本地分支管理员会一直指向它的位置 。 如果您做一个 Git 拉动, 它基本上会( 如前文所解释的) 抓取并合并您主分支的任何新更改, 并将指针移到 HEAD 。

其他回答

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允许在较新的承诺之后适用按时间顺序排列的旧承诺。 因此,存放库之间转移承诺的行为分为两步:

从远程分机复制新承诺副本到本地分机内的远程分机 。 (repo to repo operation) 主机@ remote {% text/ text/ text/ text/ progin/ master@ local 集成新承诺给本地分机( 内部分机操作) 远程/ text/ master@ local

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

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

在 Git 术语中, 第1 步是 Git 抓取, 第 2 步是 Git 合并或 Git 重新基准

git pull 是 Git 抓取和 Git 合并

简单简便的答案是,Git拉动只是git抓取,然后是git合并。

必须指出, git pull 将自动合并, 不管你喜不喜欢。 当然, 这可能导致合并冲突 。 假设您的远程是源头, 您的分支是主人 。 如果您在拉动前跳过 diff 源/ master , 您应该知道潜在的合并冲突, 并据此为您所在的分支做好准备 。

除了拉拉之外,一些工作流程还涉及重设基准,例如这一项,我从相关条款中转述如下:

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

如果你发现自己处于这种情况,你可能会被诱惑去拉拉 - rebase。除非你真的知道自己在做什么,否则我建议你不要这样做。这个警告是从git-pull的网页上发出的,版本2.3.5:

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

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

                                         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 FETCH来更新 ) 。

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

git fetch
git diff ...origin

见 git diff 关于双点... 和三点... 语法的文件。