美文网首页
Git 如何合并多个merge

Git 如何合并多个merge

作者: 柴西卡夫卡 | 来源:发表于2021-03-11 15:20 被阅读0次

    工作中会经常遇到从A分支cherry pick 几个提交到B分支,为了提交日志的简洁性,我们经常想合并这几个commit.

    image.png

    这里branch有3个提交,cherry pick到master分支后, 想合并到一个commit.

    操作步骤:
    1、找到master分支之前一个提交, commit id为 c47be0f。 也可直接执行第二步(推荐)

    image.png

    2、执行git rebase -i c47be0f。 或者省略第一步,直接执行 git rebase -i HEAD~3
    -i 表示 --interactive。

    --interactive
    Make a list of the commits which are about to be rebased. Let the user edit that list before rebasing. This mode can also be used to split commits (see SPLITTING COMMITS below).
    The commit list format can be changed by setting the configuration option rebase.instructionFormat. A customized instruction format will automatically have the long commit hash prepended to the format.

    执行后界面:

    image.png

    最上面是最早提交的。
    pick 代表使用当前提交
    squash 代表使用此次commit, 但合并到之前的commit

    image.png

    将要合并的提交改为squash 或s, 保存退出。 进入下面的界面

    image.png

    将红框出的注释改为 最终你要想要的commit message. 保存退出。

    image2.png

    3、执行 git push -f 将commit push到远程分支
    最终效果:

    image.png

    相关文章

      网友评论

          本文标题:Git 如何合并多个merge

          本文链接:https://www.haomeiwen.com/subject/ueanqltx.html