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 修改完成。

相关推荐
用户1259265423203 小时前
使用 Docker 搭建 Gitea 并实现 Git HTTP 自动登录
git
一只毛驴5 小时前
谈谈对git stash的理解?
git
长风破浪会有时呀10 小时前
Git 学习笔记
笔记·git·学习
中微子17 小时前
Git Rebase 详解:概念、原理与实战示例
git
荔枝吻21 小时前
【保姆级喂饭教程】Windows下安装Git Flow
windows·git·git flow
云和数据.ChenGuang1 天前
git中的指令解释
git
小Lu的开源日常1 天前
在 macOS 上设置 SSH 和 Git
git·macos·ssh
eleven_h1 天前
ERROR: Permission to Splode/pomotroid.git deni
git
WZF-Sang1 天前
计算机网络基础——1
网络·c++·git·学习·计算机网络·智能路由器
石头wang1 天前
如何在idea里快速地切换Windows CMD、git bash、powershell
windows·git·bash·intellij-idea