我以前开始使用git,并没有完全理解其中的复杂性。我在这里的基本问题是找出git pull和git pull——rebase之间的区别,因为添加——rebase选项似乎没有做什么非常不同的事情:只是做一个pull。
请帮助我理解其中的区别。
我以前开始使用git,并没有完全理解其中的复杂性。我在这里的基本问题是找出git pull和git pull——rebase之间的区别,因为添加——rebase选项似乎没有做什么非常不同的事情:只是做一个pull。
请帮助我理解其中的区别。
当前回答
Sometimes we have an upstream that rebased/rewound a branch we're depending on. This can be a big problem -- causing messy conflicts for us if we're downstream. The magic is git pull --rebase A normal git pull is, loosely speaking, something like this (we'll use a remote called origin and a branch called foo in all these examples): # assume current checked out branch is "foo" git fetch origin git merge origin/foo At first glance, you might think that a git pull --rebase does just this: git fetch origin git rebase origin/foo But that will not help if the upstream rebase involved any "squashing" (meaning that the patch-ids of the commits changed, not just their order). Which means git pull --rebase has to do a little bit more than that. Here's an explanation of what it does and how. Let's say your starting point is this: a---b---c---d---e (origin/foo) (also your local "foo") Time passes, and you have made some commits on top of your own "foo": a---b---c---d---e---p---q---r (foo) Meanwhile, in a fit of anti-social rage, the upstream maintainer has not only rebased his "foo", he even used a squash or two. His commit chain now looks like this: a---b+c---d+e---f (origin/foo) A git pull at this point would result in chaos. Even a git fetch; git rebase origin/foo would not cut it, because commits "b" and "c" on one side, and commit "b+c" on the other, would conflict. (And similarly with d, e, and d+e). What git pull --rebase does, in this case, is: git fetch origin git rebase --onto origin/foo e foo This gives you:
a---b+c---d+e---f---p'---q'---r' (foo)
你仍然可能会遇到冲突,但它们将是真正的冲突(在p/q/r和a/b+c/d+e/f之间),而不是b/c与b+c冲突所引起的冲突等。
答案选自(略有修改): http://gitolite.com/git-pull--rebase
其他回答
Sometimes we have an upstream that rebased/rewound a branch we're depending on. This can be a big problem -- causing messy conflicts for us if we're downstream. The magic is git pull --rebase A normal git pull is, loosely speaking, something like this (we'll use a remote called origin and a branch called foo in all these examples): # assume current checked out branch is "foo" git fetch origin git merge origin/foo At first glance, you might think that a git pull --rebase does just this: git fetch origin git rebase origin/foo But that will not help if the upstream rebase involved any "squashing" (meaning that the patch-ids of the commits changed, not just their order). Which means git pull --rebase has to do a little bit more than that. Here's an explanation of what it does and how. Let's say your starting point is this: a---b---c---d---e (origin/foo) (also your local "foo") Time passes, and you have made some commits on top of your own "foo": a---b---c---d---e---p---q---r (foo) Meanwhile, in a fit of anti-social rage, the upstream maintainer has not only rebased his "foo", he even used a squash or two. His commit chain now looks like this: a---b+c---d+e---f (origin/foo) A git pull at this point would result in chaos. Even a git fetch; git rebase origin/foo would not cut it, because commits "b" and "c" on one side, and commit "b+c" on the other, would conflict. (And similarly with d, e, and d+e). What git pull --rebase does, in this case, is: git fetch origin git rebase --onto origin/foo e foo This gives you:
a---b+c---d+e---f---p'---q'---r' (foo)
你仍然可能会遇到冲突,但它们将是真正的冲突(在p/q/r和a/b+c/d+e/f之间),而不是b/c与b+c冲突所引起的冲突等。
答案选自(略有修改): http://gitolite.com/git-pull--rebase
Git拉= Git获取+ Git合并跟踪上游分支
Git pull—rebase = Git fetch + Git rebase反对跟踪上游分支
如果你想知道git merge和git rebase有什么不同,请阅读这篇文章。
在最简单的无碰撞情况下
with rebase:在远程HEAD上重新创建本地提交,不创建合并/合并提交 Without /normal:合并并创建合并提交
参见:
男人git-pull
更准确地说,git pull使用给定的参数和运行git fetch 调用git merge将检索到的分支头合并到当前 分支。使用——rebase,它运行git rebase而不是git merge。
参见: 什么时候我应该使用git拉-rebase? http://git-scm.com/book/en/Git-Branching-Rebasing
因此,理解Merge和Rebase之间的区别非常重要。
rebase是指更改应该如何从层次结构的顶部向下传递 合并是指它们如何向上流动。
详情请参考- http://www.derekgourlay.com/archives/428
假设你在本地分支中有两个提交:
D---E master
/
A---B---C---F origin/master
“git拉”之后,会是:
D--------E
/ \
A---B---C---F----G master, origin/master
在“git pull -rebase”之后,将没有归并点g,注意D和E将成为不同的提交:
A---B---C---F---D'---E' master, origin/master