主要命令

git rebase -i 命令

开始

假如想要修改最近三次提交信息:

git rebase -i HEAD~3   //将想要修改的父提交作为参数,即`HEAD~3^`

同理,修改最近第五次提交信息:

git rebase -i HEAD~5   //将想要修改的父提交作为参数,即`HEAD~5^` 

使用上述命令后,会出现类似的界面


pick f7f3f6d 修改首页bug
pick 310154e 增加webpack配置信息
pick a5f4a0d add readme文件

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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

如果你想更改第2条commit 信息,就把第2条commit信息对应的pick 更改为edit(输入i进行编辑),然后esc+wq保存退出。

接下来,运行

git rebase --amend

运行上述命令后在弹出文本编辑界面重新提交commit信息,完成后保存退出。

接下来,运行

git rebase --continue

!!!修改完毕确认无误后,强制推送到远程!!!

git push origin master --force
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐