在实际开发中,经常会需要使用到git合并功能,git rebase可以将多个commit合并成为一个。
这里主要介绍一下git rebase -i命令的使用:
一、使用git bash命令行实现
1、先查看提交日志,选择需要合并的前一个commit版本号
git log

2、使用git rebase -i命令,进入如下页面,和操作vim一样,输入i进入编辑模式。
git rebase -i bbb57a3892703c852477ecb409f5d7017af8b72c

这里有几个使用说明(前面字母是缩写):
p,pick:使用该次提交
r,reword:使用该次提交,但重新编辑提交信息
e,edit:使用该次提交,但停止到该次提交
s,squash:将该commit和前一个commit合并
f,fixup:将该commit和前一个commit合并,但不保留该提交的注释信息
x,exec:执行shell命令
d,drop:丢弃该commit
我这里除了第一个保留pick,其余改成s就可以了。

3、保存,退出编辑页面(点击Esc键后输入:wq),进入commit message页面

之后同样是输入i进入编辑界面,修改自己的commit message

4、保存,退出。至此,git rebase一个流程走完。

网友评论