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


当前回答

enter image description here

这种互动图形表达方式非常有助于降低基点:http://ndpsoftware.com/git-cheatsheet.html

git fetch仅“ 下载” 从远程到本地仓库的更改 。git pull下载修改并将其合并到当前分支中。“在默认模式中,git pull简称为git fetch和继 继 继 继 继 继git merge FETCH_HEAD."

其他回答

最简单的说,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,来自不同的机器 / 仓库 所涉及的。

enter image description here

这种互动图形表达方式非常有助于降低基点:http://ndpsoftware.com/git-cheatsheet.html

git fetch仅“ 下载” 从远程到本地仓库的更改 。git pull下载修改并将其合并到当前分支中。“在默认模式中,git pull简称为git fetch和继 继 继 继 继 继git merge FETCH_HEAD."

缩略git 拉命令实际上是一个shortcut用于git 获取 git 获取排 排 排 排 排 排 排 排 紧 排 排git 合并git 重新基数取决于您的配置配置命令。 您可以配置您的 Git 仓库, 这样git 拉是一个接驳物,然后是一个重置物。

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使用两个命令从远程到本地获取最新版本的分支 :

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