步骤
查看历史修改
git log
使用 git 默认的编辑器显示当前分支的最近 n 个 commit 的 messages
# git rebase -i HEAD~{n} git rebase -i HEAD~3 # Displays a list of the last 3 commits on the current branch
结果示例
pick e499d89 Delete CNAME pick 0c39034 Better README pick f7fde4a Change the commit message but push the same commit. # Rebase 9fdb3bd..f7fde4a onto 9fdb3bd # # 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 # # 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
使用 reword 或者 edit 替换每个提交消息之前的 pick
pick e499d89 Delete CNAME reword 0c39034 Better README edit f7fde4a Change the commit message but push the same commit.
保存并关闭 commit 列表文件
在每一个 commit 文件写上新的 commit message,然后保存关闭。注意:如果有使用 edit 的行,在编译完成之后还要执行下列命令。
git commit --amend git rebase --continue
强制提交追加的 commits
git push -f