git: 修改commit的comment

1. 修改最后一次commit的comment

shell 复制代码
git commit --amend
  • 输入i进入编辑模式,修改后,Esc退出编辑模式,输入:wq!保存并退出

2. 修改历史的某个commit的comment

  • 在修改前,先保证没有未提交的更改,如果有,需要commit或者stash
  1. 查看commit记录
shell 复制代码
git log --oneline --graph
  1. rebase
shell 复制代码
git rebase -i <commit前一次的哈希值>
  1. 在rebase编辑器中,找到要修改comment的commit,并将前面的pick改为edit,用于标记修改的位置,然后输入:wq!保存并退出
  2. 修改comment
shell 复制代码
git commit --amend
  1. 继续rebase过程
shell 复制代码
git rebase --continue
  1. 强制推送到远程仓库
shell 复制代码
git push --force
  • 如果有多个comment需要修改,可以在第3步多修改几个edit,然后重复4和5步,最后一次性push
相关推荐
鬼手点金7 小时前
opencode-性能优化建议
java·人工智能·git·自动化·nanogpt
网络毒刘9 小时前
开源 Aider 工作流实战:Git 提交驱动的 AI 结对,与 Cursor 何时互补
git·ai编程·cursor·aider
HRTOS12 小时前
HRTOS 4.0 将长期维护:为什么版本号不再频繁变化
经验分享·git·单片机·51单片机
驭渊的小故事1 天前
linux 基础命令 + git 仓库创建和配置命令
linux·git
行者-全栈开发1 天前
华为云码道 CodeArts 实测:让 AI 用 Rust 写一个 Git 仓库健康度体检台「仓衡」
git·rust·tauri·桌面应用·ai 编程·华为云码道·codearts 代码智能体
挖掘狂人3 天前
Git 从 0 到 1:用一个小项目走完 add / commit / reset / merge / rebase / push
git·后端·github
codigger3 天前
Git 三区域模型:把 add、commit、reset、merge 一次讲透
git·github·编程·编程语言
水饺编程3 天前
第1章:开发环境搭建,在 Windows 中安装 Git
linux·c语言·汇编·git·ubuntu
idanzk3 天前
Git 推送 GitHub 报 SSL_READ /src refspec main 不匹配 完整踩坑记录
git·github·ssl
星恒随风4 天前
Linux开发工具详解(二):Git版本控制、GitHub协作与GDB调试实战
linux·笔记·git·学习·github