1

我有这个

* [cf0149e] (HEAD, branch_2) more editing
* [8fcc106] some edit
|
|  * [59e643e] (branch_2b) branch 2b
| /
|/
|  * [0f4c880] (branch_2_a) branch 2a
| /
|/
*  [a74eb2a] checkout 1
*  [9a8dd6a] added branch_2 line
|
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test

我想将这两者结合起来:

*  [a74eb2a] checkout 1
*  [9a8dd6a] added branch_2 line

合而为一

*  [a74eb2a] This is old [a74eb2a] + [9a8dd6a]

我尝试了更多我想提及的排列:reset、rebase、squash、edit。好像拉不下来 每当我成功合并它们时,合并只存在一个分支。例如,“branch_2”将以位于 HEAD~2 的所需组合结束。但是,“branch_2b”和“branch_2_a”仍然指向我要合并的两个提交。换句话说,我最终得到了一个新的提交,它是两个原始提交的合并。我想要的是让这两个提交中的所有分支现在都引用新的合并提交。

4

1 回答 1

2

在压缩这两个提交之后,你将得到一个全新的提交和自 squash 以来的历史,完全称为其他东西:

* [cf0149e] (HEAD, branch_2) more editing
* [8fcc106] some edit
|
|  * [59e643e] (branch_2b) branch 2b
| /
|/
|  * [0f4c880] (branch_2_a) branch 2a
| /
|/
*  [a74eb2a] checkout 1
*  [9a8dd6a] added branch_2 line
|
| * [cf0149e'] (HEAD', branch_2') more editing (post-squash rebase)
| * [8fcc106'] some edit (post-squash rebase)
| * [SQUASHED] "checkout 1" + "added branch_2 line"
|/
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test

请注意,其他现存的分支不受影响;那是因为你所做的只是做了一个新的压缩提交——它不会改变其他任何东西的历史。

你的 HEAD 现在指向cf0149e',它将有一个新的 SHA1 哈希,因为你已经改变了它的历史。

现在,您可以rebase将其他分支一个接一个, on SQUASHED,因为那是它们分支的点,以生成:

* [cf0149e] (HEAD, branch_2) more editing
* [8fcc106] some edit
|
|  * [59e643e] (branch_2b) branch 2b
| /
|/
|  * [0f4c880] (branch_2_a) branch 2a
| /
|/
*  [a74eb2a] checkout 1
*  [9a8dd6a] added branch_2 line
|
| * [cf0149e'] (HEAD', branch_2') more editing (post-squash rebase)
| * [8fcc106'] some edit (post-squash rebase)
| |
| |  * [59e643e] (branch_2b') branch 2b (rebased on SQUASHED)
| | /
| |/
| |  * [0f4c880'] (branch_2_a') branch 2a (rebased on SQUASHED)
| | /
| |/
| * [SQUASHED] "checkout 1" + "added branch_2 line"
|/
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test

旧的历史现在已经无关紧要了,所以我们真的有:

* [cf0149e'] (HEAD', branch_2') more editing (post-squash rebase)
* [8fcc106'] some edit (post-squash rebase)
|
|  * [59e643e] (branch_2b') branch 2b (rebased on SQUASHED)
| /
|/
|  * [0f4c880'] (branch_2_a') branch 2a (rebased on SQUASHED)
| /
|/
* [SQUASHED] "checkout 1" + "added branch_2 line"
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
于 2012-05-25T05:32:21.887 回答