git 更改远程commit信息

来源:互联网 发布:办公软件2010 编辑:程序博客网 时间:2024/05/29 03:34

在将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 bitpick 310154e updated README formatting and added blamepick 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

原创粉丝点击