修改已经 push 的 commit message

不管有没有 push,步骤是一样的。已经 push 的只是多了最后一步强制提交

git push -f

1,如何在命令行做修改

在执行 git commit --amend 后,就需要做修改,所以先来看下如何在命令行做修改。

  1. 键入 i 可以进入编辑状态。
  2. 编辑完后键入 Esc 退出编辑状态。
  3. 键入 :wq 保存退出。

2,重写最近一次的提交消息

执行下面的命令,重新编辑 commit message 后保存退出即可。

git commit --amend

3,修改旧提交或多个提交的消息

  1. 首先查看最近 n 次的 commit。n 是一个数字。
git rebase -i HEAD~n

如果中途想放弃更改,可随时使用 git rebase --abort 退出 rebase

  1. 会有如下内容展示出来
pick 6548427 xxx
pick 0c39034 xxx
pick f7fde4a Change the commit message but push the same commit.

# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
  1. 在需要更改的每个 commit message 前,将 pick 替换为 reword,接着编辑 commit message,保存后退出即可。
pick 6548427 xxx
reword 0c39034 xxx
reword f7fde4a xxx
  1. 强制 push
git push -f

以上。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

下雪天的夏风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值