git pull VS git获取git rebase [英] git pull VS git fetch git rebase

查看:87
本文介绍了git pull VS git获取git rebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个问题表示 git pull 就像是一个 git fetch + git merge



但是 git pull VS git fetch + git rebase

解决方案

实际上只是询问 git merge git rebase 之间的区别。



所以我们假设你处于一般情况 - 你已经在你的主分支上做了一些工作,然后你从原来的工作中拉出来,这也做了一些工作。在获取之后,情况如下:
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ - $ -

P - Q - R(原产地/主人)

如果你在这里合并(git pull的默认行为),假设没有任何冲突,你最终会得到这个结果:

 <$ c $ (主)
\ /
P - Q - R ---(原点/主)

如果另一方面您做了适当的rebase,您最终会得到这个结果:

   -  o  -  o  -  o  -  H  -  P  -  Q  -  R  -  A' -  B' -  C'(master)
|
(origin / master)

工作树的内容应该最终在两种情况下都是一样的;您刚创建了一个不同的历史记录。 rebase重写您的历史记录,使其看起来好像您在原来的新主分支( R )上承诺的,而不是您最初承诺的位置(ħ)。如果其他人已经从你的主分支中拉出,你永远不应该使用rebase方法。



最后,请注意,您可以为给定分支实际设置 git pull ,以使用rebase而不是merge设置配置参数分支。< name> .rebase 为true。您也可以使用 git pull --rebase 执行此操作。


Another question said git pull is like a git fetch + git merge.

But what is the difference between git pull VS git fetch + git rebase?

解决方案

It should be pretty obvious from your question that you're actually just asking about the difference between git merge and git rebase.

So let's suppose you're in the common case - you've done some work on your master branch, and you pull from origin's, which also has done some work. After the fetch, things look like this:

- o - o - o - H - A - B - C (master)
               \
                P - Q - R (origin/master)

If you merge at this point (the default behavior of git pull), assuming there aren't any conflicts, you end up with this:

- o - o - o - H - A - B - C - X (master)
               \             /
                P - Q - R --- (origin/master)

If on the other hand you did the appropriate rebase, you'd end up with this:

- o - o - o - H - P - Q - R - A' - B' - C' (master)
                          |
                          (origin/master)

The content of your work tree should end up the same in both cases; you've just created a different history leading up to it. The rebase rewrites your history, making it look as if you had committed on top of origin's new master branch (R), instead of where you originally committed (H). You should never use the rebase approach if someone else has already pulled from your master branch.

Finally, note that you can actually set up git pull for a given branch to use rebase instead of merge by setting the config parameter branch.<name>.rebase to true. You can also do this for a single pull using git pull --rebase.

这篇关于git pull VS git获取git rebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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