[英]Git rebase vs merge after rebase master on feature branch
I'm learning about rebase and saw a workflow of doing a rebase on a feature branch and then merging it into master (as an example):我正在学习 rebase 并看到了在功能分支上进行 rebase 然后将其合并到 master 的工作流程(例如):
git checkout feature
git rebase master
git checkout master
git merge feature
However I saw another similar option of the last command being (instead of 'git merge feature'):但是我看到最后一个命令的另一个类似选项是(而不是'git merge feature'):
git rebase feature
How does the last part differ in this instance?在这种情况下,最后一部分有何不同? Won't the result be the same linear timeline of the feature commits on top of master?
结果不会是在 master 之上提交的功能的相同线性时间线吗?
You may be learning about rebase, but I don't think you've quite understood it yet.您可能正在学习 rebase,但我认为您还没有完全理解它。
The command git rebase xxx
means: rebase the branch I'm on now, onto xxx
.命令
git rebase xxx
意味着:将我现在所在的分支重新设置为xxx
。 It does not change xxx
in any way.它不会以任何方式改变
xxx
。
This is confusing, because git merge xxx
means exactly the opposite: it means, merge xxx
into the branch I'm on now.这很令人困惑,因为
git merge xxx
的意思正好相反:这意味着,将xxx
合并到我现在所在的分支中。
So for example if feature
split off from master
, and master
had some commits and rebase
had some commits, then git switch feature; git rebase master
因此,例如,如果
feature
从master
分离,并且master
有一些提交并且rebase
有一些提交,那么git switch feature; git rebase master
git switch feature; git rebase master
changes the split-off point. git switch feature; git rebase master
改变了分离点。 That's effectively all it does.这实际上就是它所做的一切。
If we start with this:如果我们从这个开始:
A -- B -- C -- D -- E (master)
\
X -- Y -- Z (feature)
Then git switch feature; git rebase master
然后
git switch feature; git rebase master
git switch feature; git rebase master
results in this: git switch feature; git rebase master
结果如下:
A -- B -- C -- D -- E (master)
\
X' -- Y' -- Z' (feature)
(Note the use of the "prime" marker on the moved commits, because you cannot actually move a commit; these commits are copies of the original X, Y, and Z.) (注意在移动的提交上使用“prime”标记,因为您实际上无法移动提交;这些提交是原始 X、Y 和 Z 的副本。)
How does the last part differ in this instance?
在这种情况下,最后一部分有何不同?
In this case, there is no difference.在这种情况下,没有区别。 Any of these statements could be the 4th command and the results would be the same:
这些语句中的任何一个都可以是第 4 个命令,结果将是相同的:
git merge feature
# or
git rebase feature
# or
git reset --hard feature
# or
git checkout -B master feature
Since we're rebasing in a playful manner, note the 4 commands could be reduced to two too 2 :由于我们以一种有趣的方式进行变基,请注意 4 个命令也可以减少为两个2 :
git rebase master feature
git switch -C master feature
2 Did I really just do that? 2我真的这样做了吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.