意外推送提交:更改git提交消息 [英] Accidentally pushed commit: change git commit message

查看:163
本文介绍了意外推送提交:更改git提交消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经用 git push发布了不正确的提交信息



现在远程回购(也就是GitHub托管)也有不正确的提交消息。



我已经尝试了 git commit --amend ,但发现它在这种情况下不适用于我,因为我已经提交了额外的提交因为不正确的一个。



你会如何解决这种情况?

解决方案

最简单的解决方案(但是在做这件事之前请阅读完整答案):
$ b


  1. git rebase -i< hash-of-commit-before-the-incorrect-one>

  2. 在打开的编辑器中,将 pick 转换为 reword ,表示错误提交。 保存文件并关闭编辑器。

  3. 编辑器将再次打开ct提交消息。修正它。

  4. 保存文件并关闭编辑器。 >来更新GitHub。

这意味着你将发布一个以前发布的版本库的修改版本。如果任何人在您将错误提交给错误的提交信息之后从您的回购中拉出或取回,并且在您修复它时,他们将在稍后遇到一些困难。所以请确保在尝试此操作之前,您可以接受此后果。


In my local repo I have one commit with an incorrect commit message.

I've already published the incorrect commit message with git push.

Now the remote repo (which is GitHub-hosted) has the incorrect commit message, too.

I've already tried git commit --amend, but found that it will not work for me in this situation because I've made additional commits since the incorrect one.

How would you fix this situation?

解决方案

Easiest solution (but please read this whole answer before doing this):

  1. git rebase -i <hash-of-commit-preceding-the-incorrect-one>
  2. In the editor that opens, change pick to reword on the line for the incorrect commit.
  3. Save the file and close the editor.
  4. The editor will open again with the incorrect commit message. Fix it.
  5. Save the file and close the editor.
  6. git push --force to update GitHub.

This will mean you will be publishing a modified version of a previously published repository. If anyone pulled or fetched from your repo between when you made the mistake with the incorrect commit message, and when you fixed it, then they will experience some difficulties later. So be sure you can accept this consequence before trying this.

这篇关于意外推送提交:更改git提交消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆