English 中文(简体)
如何结合两个在基特承诺?
原标题:How to combine two commits in Git?
  • 时间:2012-05-25 05:18:06
  •  标签:
  • git

我有这个

* [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]

我尝试了更多我想提到的变式: 重置、 重置、 壁炉、 壁炉、 编辑。 似乎无法把它拉动。 只要我成功地合并了它们, 合并就只存在一个分支。 例如, “ branch_ 2” 将结束在HEAD~ 2 的预想组合中。 但是, “ branch_ 2b” 和“ branch_ 2_ a” 仍然指向我要合并的两个承诺 。 换句话说, 我结束的新承诺就是合并两个原始承诺。 我希望这两个分支中的所有分支现在都提到新的合并承诺 。

最佳回答

在粉碎这两个承诺之后, 你最终会有一个崭新的承诺 和历史,因为壁球, 完全称为别的东西:

* [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 hash, 因为你已经改变了历史 。

现在,你可以在 SQUASHED rebase 其他分支,一个接一个地生成:

* [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
问题回答

暂无回答




相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签