git修改已提交的注释
许久之前的一次提交,如果突然调查历史记录的时候发现日志写的不尽如意,想要重新编写一下,git是可以做到的,但是不太建议
步骤
-
git rebase -i xxx
这个是你要修改的提交的前一个提交哈希值,因为git rebase会切换到你指定的哈希值的后一次提交,如果你指定你想提交的哈希值,那么就会在编辑提交日志中看不到你指定的内容 -
把你要修改日志的那次提交前面的pick改成e,也就是edit,保存退出
-
运行
git commit --amend
修改日志,保存退出 -
运行
git rebase --continue
-
如果提示如下
$ git rebase --continue
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git rebase --skip'
interactive rebase in progress; onto 421b315
Last commands done (26 commands done):
pick 5a610c9 On branch master Your branch is up to date with 'origin/master'.
pick c90f882 add coding utf8 On branch master Your branch is up to date with 'origin/master'.
(see more in file .git/rebase-merge/done)
Next commands to do (15 remaining commands):
pick 76a12e4 On branch master Your branch is up to date with 'origin/master'.
pick 4d116fd 增加一个末包时间,方便统计查看 On branch dev Changes to be committed: modified: web/html/i18n/en.json modified: web/html/i18n/zh_CN.json modified: web/html/js/app.js modified: web/html/js/linkage.js
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'dev' on '421b315'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working tree clean
Could not apply c90f882... add coding utf8 On branch master Your branch is up to date with 'origin/master'.
就运行git rebase --skip
,直到出现
$ git rebase --skip
Successfully rebased and updated refs/heads/dev.
这样就表示修改完成
注意:使用git rebase
后会修改git的提交树,如果和别人一起合作开发,可能会导致大量冲突,如果是自己单独一个分支开发,可能会导致提交顺序或者提交分支之间关系发生变化,如果不是特别需要,不建议修改以前的提交日志,每次提交编写日志的时候,尽可能的详细规范。
版权声明:本文版权归作者所有,如需转载,请标明出处
分类:
Git
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
2019-08-15 [转]MySQL之——崩溃-修复损坏的innodb:innodb_force_recovery