简体   繁体   English

将两个合并提交压缩为一个合并提交?

[英]Squashing Two Merge Commits Into a Single Merge Commit?

I have the following scenario:我有以下情况:

* a278b6b (HEAD -> feature1) Change i to j
| * c9550d0 (feature3) Print only odds
|/
| * befb5e9 (feature2) 2*z in baz loop
|/
* aa36658 Print only evens

Now, what I would like to do is merge the feature1 , feature2 , and feature3 branches together into a new branch, so that this new commit contains all information from the 3 branches.现在,我想做的是将feature1feature2feature3分支合并到一个新分支中,以便这个新提交包含来自 3 个分支的所有信息。 Normally you could just do an octopus merge and get exactly what I'm looking for, but in this case, there are merge conflicts between the three branches that need to be resolved manually.通常你可以做一个章鱼合并并得到我正在寻找的东西,但在这种情况下,三个分支之间存在合并冲突需要手动解决。 So, after merging the branches one at a time in order to resolve all merge conflicts, I'm left with:因此,在一次合并一个分支以解决所有合并冲突之后,我剩下:

*   6679d6c (HEAD -> DI) merge feature3
|\
| * c9550d0 (feature3) Print only odds
* |   5b03abb merge feature2
|\ \
| * | befb5e9 (feature2) 2*z in baz loop
| |/
* / a278b6b (feature1) Change i to j
|/
* aa36658 Print only evens

where DI is the branch that all three feature branches will be merged into.其中DI是所有三个feature分支将合并到的分支。

The problem is that now I have two merge commits here: 5b03abb and 6679d6c .问题是现在我在这里有两个合并提交: 5b03abb6679d6c I'd like for there to only be a single merge commit (for cleanliness & maintenance), but the merge conflicts mean that I can't just do a straight octopus merge.我希望只有一个合并提交(为了清洁和维护),但合并冲突意味着我不能直接进行章鱼合并。 Is there a way to somehow squash the two merge commits into the same commit like you would do for standard commits, or some other merge strategy that I should be using in order to get a single merge commit with 3 parents?有没有办法以某种方式将两个合并提交压缩到同一个提交中,就像您对标准提交所做的那样,或者我应该使用的一些其他合并策略以获得与 3 个父项的单个合并提交?

Create a commit from thin air using the original branches as parents and the final tree as.... the tree :使用原始分支作为父节点并使用最终树作为......从稀薄的空气中创建提交......

git commit-tree -p a278b6b -p c9550d0 -p befb5e9 -m "some merge" 6679d6c^{tree}

That will print a commit ID.这将打印一个提交 ID。 Set the branch you want there, say, main:在那里设置你想要的分支,比如 main:

git branch -f main the-id-from-previous-command

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

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