git pull VS git fetch VS git rebase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3357122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git pull VS git fetch Vs git rebase
提问by michael
Another questionsaid git pull
is like a git fetch
+ git merge
.
另外一个问题说,git pull
就像是一个git fetch
+ git merge
。
But what is the difference between git pull
VS git fetch
+ git rebase
?
但是git pull
VS git fetch
+之间有什么区别git rebase
?
回答by Cascabel
It should be pretty obvious from your question that you're actually just asking about the difference between git merge
and git rebase
.
从您的问题中可以很明显地看出,您实际上只是在询问git merge
和之间的区别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:
因此,让我们假设您处于常见情况 - 您已经在 master 分支上完成了一些工作,并且您从 origin 中拉取了一些工作,这也做了一些工作。获取之后,事情看起来像这样:
- 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:
如果你此时合并(git pull 的默认行为),假设没有任何冲突,你最终会得到这个:
- 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.
在这两种情况下,您的工作树的内容应该是相同的;你刚刚创造了一个不同的历史导致它。rebase 重写了你的历史,使它看起来好像你是在 origin 的新主分支 ( R
)之上提交的,而不是你最初提交的地方 ( H
)。如果其他人已经从你的 master 分支中拉取了资源,你永远不应该使用 rebase 方法。
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
通过将 config 参数设置branch.<name>.rebase
为 true来为给定分支设置使用变基而不是合并。您也可以使用git pull --rebase
.
回答by harshvchawla
TLDR:
域名注册地址:
git pull
is like running git fetch
then git merge
git pull --rebase
is like git fetch
then git rebase
git pull
就像跑步 git fetch
然后git merge
git pull --rebase
就像git fetch
那时git rebase
In reply to your first statement,
回复你的第一句话,
git pull
is like a git fetch
+ git merge
.
git pull
就像一个git fetch
+ git merge
。
"In its default mode, git pull is shorthand for
git fetch
followed bygit merge
FETCH_HEAD" More precisely,git pull
runsgit fetch
with the given parameters and then callsgit merge
to merge the retrieved branch heads into the current branch"
“在默认模式下,git pull 是
git fetch
后跟git merge
FETCH_HEAD 的简写”更准确地说,使用给定的参数git pull
运行git fetch
,然后调用git merge
将检索到的分支头合并到当前分支中”
(Ref: https://git-scm.com/docs/git-pull)
(参考:https: //git-scm.com/docs/git-pull)
For your second statement/question:
对于您的第二个陈述/问题:
'But what is the difference between git pull
VS git fetch
+ git rebase
'
'但是git pull
VS git fetch
+ 有什么区别git rebase
'
Again, from same source:git pull --rebase
同样,来自同一来源:git pull --rebase
"With --rebase, it runs git rebase instead of git merge."
“使用 --rebase,它运行 git rebase 而不是 git merge。”
Now, if you wanted to ask
现在,如果你想问
'the difference between merge
and rebase
'
'merge
和rebase
'的区别
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)
这也在这里回答:
https: //git-scm.com/book/en/v2/Git-Branching-Rebasing
(改变版本历史记录方式之间的区别)