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

标签 git git-commit git-amend

我提交并推送到 repo 。后来我用git commit --amend修改了commit message,在弹窗中输入了新的message。我可以通过 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.

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

最佳答案

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

git push --force 

但是,请务必先阅读“How do I push amended commit to the remote git repo?”:如果有人已经从该存储库中提取数据,他/她将不会高兴。

替代方案在“Git: pushing amended commits”中描述。
cpeisert 所述在评论“master branch and 'origin/master' have diverged, how to 'undiverge' branches'?”中描述了您的警告信息。


2022:注意 git push --force-with-leasegit push --force 更安全。

而且你还有git push --force-if-includes (Git 2.30+),它试图确保被强制推送的内容是在检查即将被强制替换的远程引用的提交后创建的。

关于git - 执行 'git commit --amend' 后如何推送到 repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11184267/

相关文章:

git - 有没有办法配置 git commit 的输出?

git commit --amend 不询问消息

git - 如何撤消git中远程存储库的初始提交?

git --amend --no-edit 拒绝推送

git - Git如何向上游推送?

java - 使用 Git 和 Eclipse

git - Github级联 merge 的做法是什么?

git - 如何将函数声明移动到另一个文件但保留 Git 历史记录?

Git:如何在没有以前所有历史记录的情况下挑选提交

Git 日志 - 如何过滤(排除)出现在 `git log` 中的文件? (git pathspec 魔法)