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


当前回答

git fetch从远程服务器将代码从远程服务器撤回到本地仓库的跟踪分支。如果您的远程服务器被命名origin然后,这些分支将居其中;origin/,例如,origin/master, origin/mybranch-123等等。这些不是你们的现树枝,而是你们的现树枝。当地当地服务器上那些分支的复制件

git pull是否为 a 的git fetch但当时并且,还有将跟踪分支的代码合并到您当前本地版本的该分支中。如果您尚未准备好进行该修改,只需git fetch头一次。

其他回答

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

回报 :

谈到上述答案中的拉动和取回,我想分享一个有趣的把戏,

git pull --rebase

以上命令是我生命中最有用的命令 挽救了很多时间

在将您的新承诺推进到服务器之前, 请尝试此命令, 它会自动同步最新的服务器更改( 加上一个抓取 + 合并) , 并将您的承诺放在 Git 日志的顶部 。 无需担心手动拉动/ 合并 。

查找详细信息 :http://gitolite.com/git-pull--rebase

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

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" ,因为有人一直在标记 一些文章在这里。

我花了一点点时间来理解有什么区别, 但这只是一个简单的解释。master在您的本地主机是分支 。

当您克隆一个仓库时, 将整个仓库获取到本地主机主机。 这意味着当您克隆一个仓库时, 您将会有一个源/ 主指示器HEAD指向同一方向HEAD.

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

因此,区别在于:

  • 如果你做了git fetch它只会获取远程仓库中的所有更改( A) 。吉特胡布)并移动源/主指针到HEAD同时,你的当地分行长会继续指出它的位置。
  • 如果你做了git pull,它基本上可以(如先前解释的)提取(如前所解释的)并合并对主分支的任何新修改,然后将指针移到HEAD.