git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
[<upstream> [<branch>]]
git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
--root [<branch>]
git rebase (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)
1.一般场景
在topic开发完成了新的特性,需要合并到master,分支结构如下:
A---B---C topic
/
D---E---F---G master
执行命令
A'--B'--C' topic
/
D---E---F---G master
合并到master上的原来的A,B,C会变成新的A’,B‘,C’。
2…压缩x个commit,只保留一个commit
操作:git rebase -i HEAD~x
2.1.查看log:git log
2.2.进行rebase操作,其中把“update t3"这次commit直接合并到”add t3“这次操作中了。
执行git rebase -i HEAD~2,然后会自动进入vi界面。
2.3只保留一个pick,其余全改成s(quash)
3.修改完成之后保存退出,会自动进入确认页面,再次保存退出即可。
4.提交推送到远程之后再去git上提交merge request。
PS:
1.为什么没有生成merge 的commit?
使用fast-forward合并时,git不会生成merge request的commit。
2.解决冲突
rebase过程出现冲突的话,解决冲突之后不要用git commit,而是使用git rebase --continue
3.停止rebase
git rebase -abort