git pull 和 git fetch 有什么区别? git 变基?
另一个问题说git pull< /code> 就像
git fetch
+ git merge
一样。
但是 git pull
和 git fetch
+ git rebase
之间有什么区别?
Another question says that git pull
is like a git fetch
+ git merge
.
But what is the difference between git pull
and git fetch
+ git rebase
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的问题中应该可以很明显地看出,您实际上只是在询问 git merge 和 git rebase 之间的区别。
因此,让我们假设您处于常见情况 - 您已经在 master 分支上完成了一些工作,并且您从 origin 分支中提取了内容,它也做了一些工作。获取之后,事情看起来像这样:
如果你在此时合并(git pull 的默认行为),假设没有任何冲突,你最终会得到这样的结果:
如果另一方面你做了适当的变基,你最终结果是这样的:
工作树的内容在两种情况下都应该是相同的;您刚刚创建了一个不同的历史记录。变基会重写您的历史记录,使其看起来好像您已在 origin 的新主分支 (
R
) 之上提交,而不是在您最初提交的位置 (H
)。如果其他人已经从你的 master 分支中拉取,你永远不应该使用 rebase 方法。最后,请注意,您实际上可以通过将配置参数
branch..rebase
设置为 true 来为给定分支设置git pull
以使用 rebase 而不是合并。您还可以使用 git pull --rebase 来执行一次拉取操作。It should be pretty obvious from your question that you're actually just asking about the difference between
git merge
andgit 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:
If you merge at this point (the default behavior of git pull), assuming there aren't any conflicts, you end up with this:
If on the other hand you did the appropriate rebase, you'd end up with this:
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 parameterbranch.<name>.rebase
to true. You can also do this for a single pull usinggit pull --rebase
.TLDR:
git pull
就像运行git fetch
然后git merge
git pull --rebase
就像git fetch
然后git rebase
回复你的第一个语句,
git pull 就像
git fetch
+git merge
。(参考:https://git-scm.com/docs/git- pull)
对于你的第二个陈述/问题:
'但是
git pull
VSgit fetch
+git 之间有什么区别rebase
'再次,来自同一来源:
git pull --rebase
现在,如果您想问
“合并和
rebase
之间的区别”,这里也有答案:
https://git-scm.com/book/en/v2/Git -分支-变基
(改变版本历史记录方式的区别)
TLDR:
git pull
is like runninggit fetch
thengit merge
git pull --rebase
is likegit fetch
thengit rebase
In reply to your first statement,
git pull
is like agit fetch
+git merge
.(Ref: https://git-scm.com/docs/git-pull)
For your second statement/question:
'But what is the difference between
git pull
VSgit fetch
+git rebase
'Again, from same source:
git pull --rebase
Now, if you wanted to ask
'the difference between
merge
andrebase
'that is answered here too:
https://git-scm.com/book/en/v2/Git-Branching-Rebasing
(the difference between altering the way version history is recorded)