执行 git rebase -i HEAD~n ,其中n 代表想要合并的commit 节点数量,本例子为3 。执行前述命令后会出现如下内容:
$ git rebase -i HEAD~3
pick 1f6ee95 add cloud security policy translation
pick 4b59058 fix translation issue
pick f09ff89 fix translation issue
# Rebase d05c0ff..f09ff89 onto d05c0ff (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
pick 1f6ee95 add cloud security policy translation
s 4b59058 fix translation issue
s f09ff89 fix translation issue
然后根据提示,进行保存退出。在接下来出现的界面中,根据提示修改commit 信息:
# This is a combination of 3 commits.
# This is the 1st commit message:
add cloud security policy translation
# This is the commit message #2:
fix translation issue
# This is the commit message #3:
fix translation issue
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# This is a combination of 3 commits.
# This is the 1st commit message:
add cloud security policy translation
# This is the commit message #2:
# fix translation issue
# This is the commit message #3:
#fix translation issue
! [rejected] cloud-security-policy -> cloud-security-policy (non-fast-forward)
error: failed to push some refs to 'git@github.com:majinghe/cloudnative.to.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.