繁体   English   中英

如何修复Git中的问题:“更新被拒绝,因为推送的分支提示位于其远程对应的后面”

[英]How to fix issue in Git: “Updates were rejected because a pushed branch tip is behind its remote counterpart”

我正在尝试将提交推送到远程并收到此错误消息:

$  git push origin master
To git@git1.eu1.frbit.com:hbrosuru.git
! [rejected]        ab68c0485d -> master (non-fast-forward)
error: failed to push some refs to 'git@git1.eu1.frbit.com:hbrosuru.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我想通过将多个本地分支推送到这个单独的远程分支,我已经陷入困境,我想基本上清除服务器上的内容并推动整个分支的新鲜。 这是可能的,还是有更好的方法来解决这个错误?

PS。 这个远程分支托管在Fortrabbit上,所以我没有完全访问服务器来简单地删除分支并创建一个新分支,因为Fortrabbit的部署机制基于Git。

我想基本清楚服务器上的内容,并从一个新的分支推动整个分支。

这可能意味着推动力量 请注意,强制推送通常不是一件安全的事情,在推送到像GitHub这样的共享源代码存储库时尤其应该避免。 但在这种情况下,您正在推动更新PaaS服务器,这可能没问题。

您可能希望在强制推送之前使用gitkgit log --all --graph --decorate或其他一些工具以图形方式显示您的分支,只是为了确保所有内容都符合您的预期。

要强制将本地master分支推送到origin远程master分支,请运行

git push --force-with-lease origin master:master

只有当您的本地分支与您要推送的分支相关时,--force --force-with-lease参数才会导致强制推送成功。 (这可以防止意外覆盖您不知道的提交。)我强烈建议尽可能使用with-lease变体而不是旧的--force参数,这样不太安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM