【问题标题】:How can I combine commit using git rebase如何使用 git rebase 组合提交
【发布时间】:2013-05-21 17:59:37
【问题描述】:

如何使用“git rebase”在 git 中将第一次提交与第四次提交结合起来。 从我在这里读到的http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html 来看,“git rebase”中的“squash”命令只会融合到之前的提交中。

在 git 中,我有

$ git log
commit 9a30d13
commit 4a6729e
commit 4a6729e
commit 4a6729e
commit a610898

基本上,我希望 9a30d13 中的更改与 a610898 中的更改相结合,以便新的历史记录是

$ git log
commit 4a6729e
commit 4a6729e
commit 4a6729e
commit a610898 + 9a30d13

我没有推送任何东西。

谢谢。

【问题讨论】:

    标签: git


    【解决方案1】:

    当您按照链接中的说明进行交互式变基时,您也可以重新排序提交。更改顺序后,您可以将9a30d13 压缩为a610898。

    当交互式 rebase 出现时,它看起来像这样(最旧的提交在顶部):

    pick a610898 Message A
    pick 4a6729e Message B
    pick 4a6729e Message C
    pick 4a6729e Message D
    pick 9a30d13 Message E
    

    然后你重新排序:

    pick a610898 Message A
    pick 9a30d13 Message E
    pick 4a6729e Message B
    pick 4a6729e Message C
    pick 4a6729e Message D
    

    并将9a30d13 更改为squash 而不是pick:

    pick a610898 Message A
    squash 9a30d13 Message E
    pick 4a6729e Message B
    pick 4a6729e Message C
    pick 4a6729e Message D
    

    保存并退出,您就完成了。您将有机会为新的a610898 + 9a30d13 提交输入新的提交消息。

    【讨论】:

    • @0x90,这是什么意思?
    • 我的意思是如果你可以从 shell 发布所有命令和输出,但看起来你做到了。你的意思是在每一行之前使用 git 吗?
    • 不——你看到的是你运行git rebase --interactive **somesha**时得到的编辑器
    猜你喜欢
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2010-12-16
    • 2017-11-04
    • 2013-01-13
    • 2018-12-26
    相关资源
    最近更新 更多