git如何修改历史提交commit记录?可以分为以下几种情况。
1、修改最后一次提交记录
$ git commit –amend
进入命令模式,按 i 进入编辑模式,修改好commit信息后按Esc健退出编辑模式,然后:wq保存编辑的信息。最后git push到远程仓库。
2、修改最近第N次记录
rebase到需要修改的注释,这边以2为例
$ git rebase -i HEAD~2
![两次提交](http://791202.com/wp-content/uploads/2021/01/9097777777.png)
注意这里显示的顺序实是倒序。最新的提交在最下面。
![历史记录](http://791202.com/wp-content/uploads/2021/01/1606276500.jpg)
这里把我们要修改的commit,这里是倒数第二次的commit init那个。对应的pick改成e或者edit。退出保存。
![修改](http://791202.com/wp-content/uploads/2021/01/1606276500-1.jpg)
这里会提示你使用git commit –amend去修改,改好之后用git rebase –continue完成。
![用git rebase --continue完成](http://791202.com/wp-content/uploads/2021/01/9097777777-1.png)
我们把init 改成init modify再保存退出,之后用git rebase –continue完成rebase。
这时我们已经改好了倒数第二次提交信息。
![已经改好](http://791202.com/wp-content/uploads/2021/01/9097777777-3.png)
再提交push我们的修改
git log检查或者在码云上检查我们的修改。
![git log](http://791202.com/wp-content/uploads/2021/01/OIP.jpg)
git如何修改历史提交commit记录的讲解到这边就结束了。
0