当前位置:   article > 正文

通过--amend和rebase修改git commit提交的注释信息_rebase 的时候 git commit --amend

rebase 的时候 git commit --amend

简述

开发过程中,可能因为某些原因需要修改已经commit的内容。

最近一次提交

  1. 执行git commit --amend,进入注释编辑界面。
  2. 修改commit,保存提交。

倒数第n次提交

这个不好描述,以示例来说明。

通过git log --oneline得到最近的提交如下:

007d82c (HEAD -> master) add:最近一次提交,即: HEAD~1
e046fb1 add:倒数第2次提交,即: HEAD~2
10992f6 haha:倒数第3次提交,即: HEAD~3
a538e21 add:倒数第4次提交,即: HEAD~4
....
  • 1
  • 2
  • 3
  • 4
  • 5

倒数第3次提交,因为粗心,将add写成了aad

通过git rebase -i HEAD~3进入rebase界面:

pick 10992f6 haha:倒数第3次提交,即: HEAD~3
pick e046fb1 add:倒数第2次提交,即: HEAD~2
pick 007d82c add:最近一次提交,即: HEAD~1

# Rebase a538e21..007d82c onto a538e21 (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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

将目标行的pick修改为edit或者reword,并修改后面的commit内容,修改完成之后如下:

edit 10992f6 add:倒数第3次提交,即: HEAD~3
pick e046fb1 add:倒数第2次提交,即: HEAD~2
pick 007d82c add:最近一次提交,即: HEAD~1

# Rebase a538e21..007d82c onto a538e21 (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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

保存退出,完成修改。

**特别提示:**可以把HEAD~N中的N设置的大些,只要能包含目标提交即可。

修改多次提交

情景一:这些错误提交相互间隔较近

HEAD~N中的N设置的大些,一次性把错误的提交都包含,通过一次rebase完成修改。

情景二:这些错误提交很分散

通过多次rebase完成修改。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/407827
推荐阅读
相关标签
  

闽ICP备14008679号