简体   繁体   English

合并后如何变基?

[英]How can I rebase after a merge?

I'm reading the Pro Git book and get stuck on rebasing.我正在阅读 Pro Git 的书,并被困在变基上。

Below is the scenario:下面是场景: 在此处输入图像描述

so two branches have already merged.所以两个分支已经合并了。 Then the book says after we make a merge, we can still change mind to rebase C4 to C5 as:然后书上说,在我们进行合并后,我们仍然可以改变主意,将 C4 重新设置为 C5,如下所示: 在此处输入图像描述

But I tried to replicate the rebasing and found out that after a merge is made, I cannot rebase anymore, if I try:但我试图复制变基,发现在合并后,如果我尝试,我不能再变基:

git checkout branch_on_c4 git 结帐 branch_on_c4

git rebase branch_on_c5 git rebase branch_on_c5

I got no new commit of C4' , and the message is:我没有新的C4'提交,消息是:

First, rewinding head to replay your work on top of it首先,倒带头在上面重播你的工作

Applying: add申请:添加

Using index info to reconstruct a base tree使用索引信息重建基础树

Falling back to patching base and 3-way merge回退到修补基础和 3 路合并

No changes -- Patch already applied**无变化——已应用补丁**

If I didn't merge two branches first, I have no problem with rebasing C4 on C5.如果我没有先合并两个分支,那么在 C5 上重新定位 C4 是没有问题的。 But once I have done the merge, I cannot rebase anymore, so how does the author or what command does the author use to do the rebasing after merging?但是一旦我完成了合并,我就不能再变基了,那么作者如何或作者在合并后使用什么命令来进行变基呢?

tl;dr tl;博士

How can I rebase after a merge?合并后如何变基?

You don't need to, and that isn't what the book said.你不需要,这不是书上说的。 Just throw the merge away if you didn't like it, and rebase instead .如果您不喜欢合并,只需将其丢弃,然后改为rebase 。


Then the book says after we make a merge, we can still change mind to rebase然后书上说,在我们进行合并后,我们仍然可以改变主意变基

No, it doesn't.不,它没有。

It says

... if instead of doing a merge when [ this happens ] we run git rebase teamone/master ... ...如果不是在[ 发生这种情况]时进行合并,而是运行git rebase teamone/master ...

That is, instead of merging, not after .也就是说,而不是合并,而不是after

So, you'd either have to run fetch and identify the potential problem in advance, or run a normal merge pull , decide it's a mess and throw it away to start again with:因此,您要么必须运行fetch并提前识别潜在问题,要么运行正常的 merge pull ,确定它是一团糟并将其扔掉以重新开始:

git reset --hard HEAD@{1}

(I tend to avoid the HEAD~1 syntax for merges, because I don't want to have to think about which parent is which - the reflog syntax for "previous value of HEAD" is simpler IMO). (我倾向于避免使用HEAD~1语法进行合并,因为我不想考虑哪个父级是哪个父级 - “HEAD 的先前值”的 reflog 语法更简单 IMO)。

I assume that you are referring to Fig. 45 and Fig. 46 here: Git Branching Rebasing我假设您在这里参考图 45 和图 46: Git 分支变基

Next, the person who pushed the merged work decides to go back and rebase their work instead;接下来,推送合并工作的人决定将 go 退回并重新调整他们的工作; they do a git push --force to overwrite the history on the server.他们执行 git push --force 以覆盖服务器上的历史记录。 You then fetch from that server, bringing down the new commits.然后,您从该服务器获取,降低新的提交。

That person most likely did something to undo the merge, for example:该人很可能做了一些事情来撤消合并,例如:

git reset --hard HEAD~1

Then it was possible to execute rebase and push --force .然后可以执行rebasepush --force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM