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
相关推荐
易雪寒30 分钟前
IDEA在git提交时添加忽略文件
java·git·intellij-idea
徒步僧2 小时前
mac中文件夹怎么显示.git隐藏文件
git·macos
int WINGsssss1 天前
Git使用
git
用户0760530354381 天前
Git Revert:安全移除错误提交的方式
git
Good_Starry1 天前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣2 天前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z2 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去2 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔2 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康2 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea