如何线性化“分裂的"图?在Git中合并历史? [英] How to linearize "splintered" merging history in Git?

查看:111
本文介绍了如何线性化“分裂的"图?在Git中合并历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定很明显,但是我发现没有办法.每本手册都描述了在现有分支或简单的交互式rebase之上建立基础,仅此而已.假设我有一个像这样的菱形git历史:

It must be very obvious, but I found no way to do it. Every manual describes rebasing onto a top of existing branch or simple interactive rebase and that's all. Suppose, I have a diamond-shaped git history like that:

*   949430f Merge commit (D) (HEAD, mybranch)
|\  
| * e6a2e8b (C)
* | 3e653ff (B)
|/  
*   9c3641f Base commit (A)

我想存档历史记录:

*   949430f Combined commit (BCD)
|  
*   9c3641f Base commit (A)

提交B和C可能完全融化或丢弃,没关系,我只想保留结果.另外,我也不想因为令人讨厌的冲突解决而还原提交.

Commits B and C may be melted or discarded at all, doesn't matter, I want to preserve only the result. Also I DO NOT want to revert commits because of nasty conficts resolving.

这是我尝试过的事情:

1)我不能通过简单地挤压B和C来解决这个问题

1) I can't archeve that by simple squashing B and C

git rebase -i HEAD~2
...
p 3e653ff (B)
f e6a2e8b (C)
...
Could not apply a91f3a4

嗯,这有点可以理解,存在一些冲突.

Well, that's somewhat understandable, there're some conflicts.

2)我无法通过挤压来存档.

2) I can't archeve that by squashing.

git rebase -i -p HEAD~3
...
pick 9c3641f Base commit (A)
f 3e653ff (B)
f e6a2e8b (C)
pick 949430f Merge commit (D)
...
error: unable to match a91f3a4...

3)我什至不能丢掉B和C

3) I can't even discard B and C

git rebase -i -p -m HEAD~3
...
pick 9c3641f Base commit (A)
#pick 3e653ff (B)
#pick e6a2e8b (C)
pick 949430f Merge commit (D)
...
error: Commit 949430f is merged but option -m is not set.
fatal: cherry-pick failed
Could not pick 4f3e6231b5cecf57434613ca3afd2a21ba375eb9

为什么?这是选项"-m" ...

Why? Here is option "-m"...

有人知道如何解决这个问题吗?

Does anyone know how to solve this problem?

推荐答案

您想要的是git reset --soft(加上 VonC的答案.

What you want is git reset --soft (plus a commit as noted by aragaer). Despite the different circumstances in the question, see this answer by VonC.

这篇关于如何线性化“分裂的"图?在Git中合并历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆