git 更改远程commit信息

在将commit信息push到origin之后如果想更改commit信息可以使用git rebase -i 命令。具体方法如下
修改最近一次commit信息

git commit --amend

使用以上命令后,你会进入文本编辑器,修改commit信息保存后就可以更新commit信息
修改多条commit信息
例如,如果想要修改最近三次提交信息,或者那组提交中的任意一个提交信息,将想要修改的最近一次提交的父提交作为参数传递给 git rebase -i命令,即HEAD~2^ 或 HEAD~3。

git rebase -i HEAD~3

使用上述命令后,会出现类似的界面

pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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

如果你想更改第一条commit 信息,把第一条commit信息对应的pick 更改为edit然后保存退出,运行

git rebase --amend

运行上述命令后在弹出文本编辑界面重新提交commit信息,完成后保存退出。运行

git rebase --continue

所有的commit信息都修改完之后运行一下命令将更改推送到远程

git push origin master --force

git commit 信息规范
关于git commit信息规范可以参照
https://chris.beams.io/posts/git-commit/#separate

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值