1

命令

git rebase -i HEAD~4

或者

git rebase -i bddesdd6 #要合并的提交的上一条提交ID

合并(vi编辑器模式)

pick bddebfb1 退出修改
f 68326b8c 接口修改
f 699501f7 接口修改
f 784e86b3 接口修改

# Rebase 2b8d14b7..784e86b3 onto 784e86b3 (4 commands)
#
# Commands:
# p, pick <commit> = use commit
......

主要看这里的合并方式
根据描述 用f(fixup) (使用这个提交,但合并到前一个提交,并且忽略备注)

# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was

如果中途发生异常,比如还没完成关闭了终端,可随时中断重新rebase

git rebase --abort

同步到远程(确保此分支没有别的提交或者只有你在用)

git push origin branchName -f

zpfei
186 声望7 粉丝

往事如风~