执行'git commit --amend'后如何推送到repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11184267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:07:27  来源:igfitidea点击:

How to push to repo after doing 'git commit --amend'

gitgit-commitamend

提问by user1479142

I made a commit & pushed to repo. Later I modified the commit message by using git commit --amend, In the pop-up window I entered the new message. I could see the new message via git log. After all this process, my git statusshows like this. I don't know how to push this change to repo.

我做了一个提交并推送到回购。后来我通过使用修改了提交消息git commit --amend,在弹出窗口中我输入了新消息。我可以通过git log. 在所有这些过程之后,我的git status表演是这样的。我不知道如何将此更改推送到 repo。

On branch master
Your branch and `origin/master` have diverged,
and have 1 and 1 different commit(s) each, respectively.

Expecting a feasible solution for this.

期待一个可行的解决方案。

回答by VonC

If you are ok with modifying the history on the remote repo (as in, you just pushed that commit, and no new commits were made), you can try a

如果您可以修改远程存储库上的历史记录(例如,您只是推送了该提交,并且没有进行新的提交),您可以尝试

git push --force 

However, do read first "How do I push amended commit to the remote git repo?": if anyone already pulled from that repo, he/she won't be happy.

但是,请先阅读“如何将修改后的提交推送到远程 git 存储库?”:如果有人已经从该存储库中提取,他/她将不会高兴。

An alternative is described in "Git: pushing amended commits".
As mentioned by cpeisertin the comment "masterbranch and 'origin/master' have diverged, how to 'undiverge' branches'?" described your warning message.

Git:推送修正的提交”中描述了另一种选择。
正如cpeisert在评论中提到的“master分支和‘ origin/master’已经分叉,如何‘解除分支’?”描述了您的警告信息。