注意:合并的时候尽量不要合并其他人的提交,因为合并之后不会保留,更新完之后其他人的代码会有冲突,需要删了重建
步骤一:查看commit提交记录 (复制需要合并的id)
git log --oneline
--oneline参数,代表将每个commit压缩成一行,只显示commitID和commit message的第一行
步骤二:执行rebase -i 打开交互
git rebase -i <commit ID>
例如:git rebase -i d5d1335
步骤三:根据需要改写命令,把pick改为s/squash
pick a50f132 第2次commit
s 73c98f9 第3次commit
s 25d5ae5 第4次commit
s d5ace53 第5次commit
# Rebase d5d1335..d5ace53 onto d5d1335 (4 command)
#
# 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 [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# 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
# specified); use -c <commit> to reword the commit message
步骤四:强制推送
git push -f
如果遇到错误需要先解决冲突:git status
最后有个保险操作:git reset
为什么要执行这个操作?