两者之间有什么区别?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 拉命令实际上是一个shortcut用于git 获取 git 获取排 排 排 排 排 排 排 排 紧 排 排git 合并git 重新基数取决于您的配置配置命令。 您可以配置您的 Git 仓库, 这样git 拉是一个接驳物,然后是一个重置物。

之间唯一的差别git pullgit fetch是:

git pull从远程分支拉出并合并。

git fetch仅从远程分支获取取取, 但它不合并

i. e. git pull = git 获取 + git 合并...

我们简单地说:

git pull == git fetch + git merge

如果你逃跑git pull中,您不需要将数据合并到本地数据。如果运行git fetch这意味着你必须跑git merge获取本地机器的最新代码。 否则, 本地机器代码不会在不合并的情况下被更改 。

所以在 Git Gui 中, 当您获取时, 您必须合并数据 。 获取本身不会在本地修改代码 。 您可以检查当您通过一次获取并查看来更新代码时, 是否更新了代码; 代码不会改变 。 然后您将合并... 您将会看到修改后的代码 。

这张图能帮上忙git pull基本上等于git fetch时当时git merge

This graphic could be of help. git pull is essentially equivalent to git fetch then git merge

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也许更安全,因为在合并之前,我们可以看到变化,决定是否合并。