900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 通过--amend和rebase修改git commit提交的注释信息

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

时间:2018-12-13 22:40:27

相关推荐

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

简述

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

最近一次提交

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

倒数第n次提交

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

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

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

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

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

pick 10992f6 haha:倒数第3次提交,即: HEAD~3pick e046fb1 add:倒数第2次提交,即: HEAD~2pick 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

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

edit 10992f6 add:倒数第3次提交,即: HEAD~3pick e046fb1 add:倒数第2次提交,即: HEAD~2pick 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

保存退出,完成修改。

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

修改多次提交

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

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

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

通过多次rebase完成修改。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。