Git 如何合并多个merge

工作中会经常遇到从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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容