比如要修改最近三次提交的作者、邮箱、提交时间等, 在代码目录下执行
git rebase -i HEAD~3
会显示最近提交的三次记录,注意顺序是倒序的
例如显示
pick 4cbce22 add 2.html
pick 01fffe5 add new line
pick 8e567b9 add line
# Rebase 67571e9..8e567b9 onto 67571e9 (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 4cbce22 add 2.html
pick 01fffe5 add new line
pick 8e567b9 add line
改为
edit 4cbce22 add 2.html
edit 01fffe5 add new line
edit 8e567b9 add line
将 pick
改为 edit
表示将编辑这几条记录, 修改后 :wq
保存退出
开始修改提交日志描述:
git commit --amend
或者使用如下命令可以同时修改作者、邮箱及日期:
git commit --amend --author "baurine <2008.hbl@gmail.com>" --date="$(date -R)"
修改完成,执行:
git rebase --continue
如果选择了多条要编辑的记录会进入下一条,使用同样的方法修改提交记录,
当所有要编辑的记录都修改完后,将显示 Successfully rebased and updated refs/heads/master.
, 修改就完成了。
转载请注明:大后端 » 用 git rabase 修改提交历史