简体   繁体   English

Git:在此Git速查表的背景下,获取与拉取

[英]Git: fetch vs. pull, in the context of this Git cheat sheet

I'm understanding the difference between a git fetch and git pull (the former leaves local branch untouched, the latter merges changes into local branch), but I'm bit confused about this cheat sheet: 我了解git fetch和git pull之间的区别(前者保留了本地分支不变,后者将更改合并到了本地分支中),但是我对此备忘单感到有些困惑:

在此处输入图片说明

There is an arrow directly underneath "fetch", which makes it look like fetch and pull are identical functions. “提取”正下方有一个箭头,这使它看起来像提取和拉取是相同的功能。 From what I understand, only the bottom-most arrow should be "pull". 据我了解,只有最底部的箭头应该是“拉”。 Does anyone else agree that the arrow below "fetch" shouldn't be there? 是否有其他人同意“获取”下方的箭头不应存在? If it should, can you please explain why? 如果可以,请您解释一下原因?

Pull belongs to both arrows (the ones it borders). 拉属于两个箭头(与之相邻的箭头)。 Pull includes a fetch; 拉包括获取; it updates your local repository (same as fetch) and it also updates your local workspace. 它会更新您的本地存储库(与访存相同),还会更新您的本地工作区。

What it is trying to say with the arrow beneath the fetch is that when you do a pull , you update both the local repo as well as the workspace. 尝试使用fetch下方的箭头表示的是,当您执行pull ,您将同时更新本地存储库和工作区。 Hence, a pull both for local repo & workspace. 因此, pull都为本地回购和工作区。

A git pull is basically a git fetch & git merge . git pull本质上是git fetchgit merge

Here is Oliver Steele's image of how all it all fits together : 这是奥利弗·斯蒂尔Oliver Steele)关于所有这些如何组合的图像

在此处输入图片说明

Link to follow. 链接跟随。

Both fetch and merge sync remote repo to local repo which is what diagram conveys. fetchmergemerge远程回购同步到本地回购,这正是该图所传达的。 So its correct as per diagram. 因此,它按照图表是正确的。 As you mentioned, former don't merge and later merge is after syncing to local repo. 如前所述,前者不合并,而后合并则是同步到本地仓库后。

From git docs : git docs

Incorporates changes from a remote repository into the current branch. 将更改从远程存储库合并到当前分支。 In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. 在其默认模式下,git pull是git fetch的缩写,其后是git merge FETCH_HEAD。 More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. 更精确地讲,git pull使用给定的参数运行git fetch并调用git merge将检索到的分支头合并到当前分支中。 With --rebase, it runs git rebase instead of git merge. 使用--rebase,它将运行git rebase而不是git merge。

So git pull do two work first git fetch and second git merge. 所以git pull做两个工作,第一个git fetch和第二个git merge。 Fetch update your local repository and merge update your working directory. 获取更新您的本地存储库,并合并更新您的工作目录。 So both arrows represent pull is fine. 因此,两个箭头都代表拉动效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM