在git中,获取与pull相比有何不同,以及merge是如何与rebase不同的? [英] In git how is fetch different than pull and how is merge different than rebase?

查看:114
本文介绍了在git中,获取与pull相比有何不同,以及merge是如何与rebase不同的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是无法理解这一点。我一直在网上和书上看很多东西,只是没有留在我的脑海。有人可以给我以下的虚拟版本:


  • git fetch vs pull

  • git合并与rebase


解决方案

抓取vs拉



fetch 将从远程*分支下载任何更改,更新您的存储库数据,但不改变本地*分支。



pull 将执行 fetch ,另外 merge
$ b

有什么不同? pull 更新您的本地分支与拉动分支的变化。 fetch 不会推进您的本地分支。



合并vs rebase



给出以下历史记录:

 
C --- D --- E本地
/
A --- B --- F --- G remote

merge 一起加入两个发展历史。它通过在远程分支之上分叉后重播本地分支上发生的更改并将结果记录在新提交中来实现此目的。此操作保留了每次提交的祖先。



合并的效果是:

 
C --- D --- E本地
/ \
A --- B --- F --- G --- H remote

rebase 将接受您本地存在的提交分支并将其重新应用于远程分支之上。这个操作重写本地提交的祖先。



rebase 的作用是: p>

 
C' - D' - E'本地
/
A --- B --- F- --G remote

有什么区别?合并不会改变提交的祖先。 rebase
会重写您本地提交的血统。
$ b * 这个解释假定当前分支是本地分支,并且分支指定为 fetch pull merge rebase 是一个远程分支。这是通常的情况。例如, pull 将从指定的分支下载任何更改,更新您的存储库并 merge 当前分支的变化。


I just cant understand this. I been reading a lot on the web and books and something is just not staying in my head. Can someone please give me the dummy version of the following:

  • git fetch vs pull
  • git merge vs rebase

解决方案

fetch vs pull

fetch will download any changes from the remote* branch, updating your repository data, but leaving your local* branch unchanged.

pull will perform a fetch and additionally merge the changes into your local branch.

What's the difference? pull updates you local branch with changes from the pulled branch. A fetch does not advance your local branch.

merge vs rebase

Given the following history:

          C---D---E local
         /
    A---B---F---G remote

merge joins two development histories together. It does this by replaying the changes that occurred on your local branch after it diverged on top of the remote branch, and record the result in a new commit. This operation preserves the ancestry of each commit.

The effect of a merge will be:

          C---D---E local
         /         \
    A---B---F---G---H remote

rebase will take commits that exist in your local branch and re-apply them on top of the remote branch. This operation re-writes the ancestors of your local commits.

The effect of a rebase will be:

                  C'--D'--E' local
                 /
    A---B---F---G remote

What's the difference? A merge does not change the ancestry of commits. A rebase rewrites the ancestry of your local commits.

* This explanation assumes that the current branch is a local branch, and that the branch specified as the argument to fetch, pull, merge, or rebase is a remote branch. This is the usual case. pull, for example, will download any changes from the specified branch, update your repository and merge the changes into the current branch.

这篇关于在git中,获取与pull相比有何不同,以及merge是如何与rebase不同的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆