我如何结合使用git rebase提交 [英] How can I combine commit using git rebase

查看:95
本文介绍了我如何结合使用git rebase提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



在git中,我有

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

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

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



谢谢。

解决方案

当你可以按照你的链接描述的方式进行交互式重新分配,你也可以对提交进行重新排序。改变订单后,您可以将 9a30d13 压缩到 a610898



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

 选择a610898消息A 
选择4a6729e消息B
选择4a6729e消息C
选择4a6729e消息D
选择9a30d13消息E

然后重新排列它们:

  pick a610898消息A 
pick 9a30d13消息E
pick 4a6729e消息B
pick 4a6729e消息C
pick 4a6729e消息D

然后将 9a30d13 更改为压扁而不是 pick

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

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


How can I combine 1st commit with 4th commit in git using 'git rebase'. From what I read here http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html, the 'squash' command in 'git rebase' only meld into previous commit.

in git, I have

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

Basically, I want changes from 9a30d13 to combine with changes in a610898, so that the new history is

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

I have not pushed anything.

Thank you.

解决方案

When you do an interactive rebase as described at your link, you can reorder the commits, too. Once you change the order, you can squash 9a30d13 into a610898.

When the interactive rebase comes up, it will look something like this (with the oldest commits on top):

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

You then reorder them:

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

And change 9a30d13 to squash rather than pick:

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

Save & exit, and you're done. You'll get a chance to enter a new commit message for your new a610898 + 9a30d13 commit.

这篇关于我如何结合使用git rebase提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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