修改已经 push 的 commit message
不管有没有 push,步骤是一样的。已经 push 的只是多了最后一步强制提交:
git push -f
1,如何在命令行做修改
在执行 git commit --amend
后,就需要做修改,所以先来看下如何在命令行做修改。
- 键入
i
可以进入编辑状态。 - 编辑完后键入
Esc
退出编辑状态。 - 键入
:wq
保存退出。
2,重写最近一次的提交消息
执行下面的命令,重新编辑 commit message 后保存退出即可。
git commit --amend
3,修改旧提交或多个提交的消息
- 首先查看最近 n 次的 commit。n 是一个数字。
git rebase -i HEAD~n
如果中途想放弃更改,可随时使用 git rebase --abort
退出 rebase
- 会有如下内容展示出来
pick 6548427 xxx
pick 0c39034 xxx
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
- 在需要更改的每个 commit message 前,将
pick
替换为reword
,接着编辑 commit message,保存后退出即可。
pick 6548427 xxx
reword 0c39034 xxx
reword f7fde4a xxx
- 强制 push
git push -f
以上。