意外推送commit:更改git commit消息(Accidentally pushed commit: change git commit message)

编程入门 行业动态 更新时间:2024-10-25 12:21:01
意外推送commit:更改git commit消息(Accidentally pushed commit: change git commit message)

在我的本地回购中,我有一个提交错误的提交信息。

我已经用git push发布了错误的提交消息。

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

我已经尝试过git commit --amend ,但是发现在这种情况下,我不会为我工作,因为我从错误的一个进行了额外的提交。

你会如何解决这种情况?

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?

最满意答案

最简单的解决方案( 但请在阅读完整的答案之前 ):

git rebase -i <hash-of-commit-preceding-the-incorrect-one> 在打开的编辑器中,更改pick以reword错误提交的行。 保存文件并关闭编辑器。 编辑器将再次打开不正确的提交消息。 修理它。 保存文件并关闭编辑器。 git push --force更新GitHub。

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

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

git rebase -i <hash-of-commit-preceding-the-incorrect-one> In the editor that opens, change pick to reword on the line for the incorrect commit. Save the file and close the editor. The editor will open again with the incorrect commit message. Fix it. Save the file and close the editor. 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.

更多推荐

本文发布于:2023-08-06 22:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意外   消息   git   commit   message

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!