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


当前回答

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

其他回答

enter image description here

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

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

我也为此挣扎过。事实上,我来到这里时,用谷歌搜索了完全相同的问题。阅读了所有这些答案,终于在我脑海中画出了一张图片,我决定试着从下面看2个储存库和1个沙箱的状况,以及一段时间以来在看它们的版本时所采取的行动。这就是我所想出来的。如果我在任何地方搞砸了,请纠正我。

三个邮箱有一个接听器:

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - fetch               -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     -                     -
- @ R01             -     - @ R01+              -     - @R01+               -
---------------------     -----------------------     -----------------------

三号邮局拉一拉一拉

---------------------     -----------------------     -----------------------
- Remote Repo       -     - Remote Repo         -     - Remote Repo         -
-                   -     - gets pushed         -     -                     -
- @ R01             -     - @ R02               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Repo        -     - Local Repo          -     - Local Repo          -
- pull              -     -                     -     - pull                -
- @ R01             -     - @ R01               -     - @ R02               -
---------------------     -----------------------     -----------------------

---------------------     -----------------------     -----------------------
- Local Sandbox     -     - Local Sandbox       -     - Local Sandbox       -
- Checkout          -     - new work done       -     - merged with R02     -
- @ R01             -     - @ R01+              -     - @R02+               -
---------------------     -----------------------     -----------------------

这帮助我理解了为什么买东西很重要。

初学者的简单图形化代表,

enter image description here

在这里,

git pull  

将会从仓库获取代码 并重新基础与您的本地... 在git拉动中,有 可能性创造新的承诺。

但是在,

git 获取 git 获取

将会从存储库获取代码, 我们需要通过使用git rebase

eg: 我要从服务器主机取回它, 并在本地主机重标 。

1) git pull( 重基将自动完成) :

git pull origin master

在这里来源来源是你的远程回寄师父您的分支

2) git 获取( 需要手动重标) :

git fetch origin master

它会从源代码中获取服务器更改。 它会位于本地, 直到您自己重新定位它。 我们需要通过检查代码手动来修正冲突 。

git rebase origin/master

这将会将代码重设为本地代码。 在确保您在正确的分支之前。

简单解释:

git fetch

获取元数据。 如果您想要检查最近创建的分支, 您可能需要在退出前进行获取 。

git pull

从远程获取元元数据,并将文件从远程移动并合并到分支

有时视觉表现会有所帮助。

enter image description here