修改 git 历史提交的信息

使用 git rebase -i HEAD~n 命令
n数字表示要修改前 n 次所有的提交
i 是 interactive,交互的意思

从根节点开始 git rebase -i --root

pick ac0fcc6 add file2
pick a0cbfbe add file3
pick 16ee6eb add file4
# Rebase d57f11f..16ee6eb onto d57f11f (3 command(s))
#
# 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

将要修改的 pick 改成 edit 或 e,保存退出。

保存上面的修改并退出后,git 会依次执行上面的操作,当操作为 pick 时,直接 commit。当操作为 edit 时,会中断,并提示以下信息:

You can amend the commit now, with
    git commit --amend 
Once you are satisfied with your changes, run
    git rebase --continue

这里的意思是说,你可以使用 git commit --amend 来修改此次提交,修改以后,觉得满意了,执行 git rebase --continue 继续剩下的流程。

由于我们的主要目的是修改提交者的信息,因此光用 git commit --amend 是不够的,我们要使用 git commit --amend --author “作者a@q.com” 这样的操作,这一点是修改提交者信息的关键所在。

使用上面的命令成功修改此次提交的提交者信息后,一定要记得执行 git rebase --continue 继续。

最终完成以后提示如下:

$ git rebase --continue
Successfully rebased and updated refs/heads/master.

commit --amend --author "leo<13708867890>"

git rebase --continue
Successfully rebased and updated refs/heads/master.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

漫游游²º¹²

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

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

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

打赏作者

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

抵扣说明:

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

余额充值