Git 修改历史 commit message

一. 修改最新的 commit log

修改最近一次commit message,
直接使用命令 `git commit --amend` 就可以完成修改

二. 修改历史 commit log

  1. 查看日志(按 q 退出)

    bash 复制代码
    git log --oneline
    # 查看5步的log。
    git log --oneline -5
  2. 选择要修改的commit 信息

    bash 复制代码
    # 要修改的 commit log 在三步之内:
    git rebase -i HEAD~3。
    # 指定某个commit
    git rebase fe19172^ --interactive
  3. 开始编辑,修改commit信息
    a. 按 i 进入编辑模式(其实此时在 VIM 编辑器中操作了), 将此行前面的pick改为edit, 可以修改多个
    :wq保存退出编辑, HEAD会返回该提交处

    b. 退出VIM,在 终端 中,执行 git commit --amend ,然后修改 commit信息, :wq保存退出
    c. 运行 git rebase --continue

  4. 验证

    显示修改成功, 重新运行git log --oneline 后检查是否修改正确

  5. 推送远程仓库

    如果已经push至远程分支, 则需要运行 git push -f 覆盖远程分支

至此,历史commit message 修改完成。

相关推荐
萌狼蓝天几秒前
git恢复到之前提交的记录
git
是程序喵呀6 分钟前
git的基本使用
大数据·git
a未来永远是个未知数9 分钟前
构建机部署之git安装(Linux)
linux·git·elasticsearch
丁总学Java11 分钟前
命令行运行git reflog(reference log)报错的解决办法
git·reference·log·reflog
右璇6 小时前
Git 常用命令备忘
git
小鹿( ﹡ˆoˆ﹡ )10 小时前
Git使用简介及相关命令
git
Marvin-Fox11 小时前
GIT 使用相关技巧记录
git
不想步入秃头的年龄1 天前
Git学习(常用的一些命令)
git·学习
pcdd1 天前
【Git】取消追踪多个文件或目录
git
weixin_471997271 天前
Git 运用小知识
git