这2个commits不是靠在一起的,中间隔着其它commits,请问如何合并为1个?
假设 commits 是 A-B-C-D-E-F ,想修改为 A-C-D-BE-F
后来一想,既然连续的2个 commits 可以合并,那可以先把2个不连续的 commits 变成连续的 commits ,然后合并。
git rebase 的操作命令如下:
1)运行命令 git rebase -i HEAD~6
2)出现下面的 rebase 交互编辑器界面
pick ae4f7d9 A pick 5488927 B pick 4095996 C pick 7bf443e D pick d2951f9 E pick 4d9f654 F
3)调整上面 commits 的顺序,使 B 与 E 成为连续的 commits
pick ae4f7d9 A pick 4095996 C pick 7bf443e D pick 5488927 B pick d2951f9 E pick 4d9f654 F
4)使用 squash 将 B 与 E 合并
pick ae4f7d9 A pick 4095996 C pick 7bf443e D pick 5488927 B squash d2951f9 E pick 4d9f654 F
5)出现下面的修改合并后的 commit message 的界面
# This is a combination of 2 commits. # The first commit's message is: B # This is the commit message #2: E
修改为
# This is a combination of 2 commits. # The first commit's message is: BE # This is the commit message #2: #E
6)rebase 完成后就达到了想要的效果
commit 87dd45819694c6ed4fba26685e2f7a8bb934b62a Date: Fri Jan 13 15:27:30 2017 +0800 F commit 015b6ca5c57a0667547faa0944e08aec79213aaf Date: Thu Jan 12 21:34:38 2017 +0800 BE commit 5f27c8d8b60ffe520981d6c90082f4f2d0320346 Date: Fri Jan 13 11:09:18 2017 +0800 D commit a101a5ef2baf11c0681a218b69e495b086a86979 Date: Thu Jan 12 15:34:11 2017 +0800 C commit ae4f7d92c2c7a96eb9636f8c76f4912e45b0d73e Date: Thu Jan 12 18:16:54 2017 +0800 A
厉害了,我的村长
马克
中间的不合并?
A-B-C-D-E-F
只合并BE?
效果是A-C-D-F-B-E?
http://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one
是的,效果是A-C-D-BE-F。
这个stackoverflow链接中针对的是连续的2个commits