如何解决Git中的问题:“更新被拒绝是因为推送的分支提示位于其远程对方后面” [英] How to fix issue in Git: "Updates were rejected because a pushed branch tip is behind its remote counterpart"

查看:16912
本文介绍了如何解决Git中的问题:“更新被拒绝是因为推送的分支提示位于其远程对方后面”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ git push origin master $ b 

我尝试将提交推送到远程并获取此错误消息: $ b到git@git1.eu1.frbit.com:hbrosuru.git
! [rejected] ab68c0485d - >主(非快进)
错误:无法将某些参考推送到'git@git1.eu1.frbit.com:hbrosuru.git'
提示:更新被拒绝是因为推送的分支提示是在其远程
背后:对应。检查此分支并在再次推送之前集成远程更改
提示:(例如'git pull ...')。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。

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



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


我想清楚了解服务器上的内容,并将整个分支从新鲜的分支中推出。




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



您可能想要使用 gitk git log --all --graph --decorate ,或者在推动之前的其他一些工具,只是为了确保一切看起来像你期望的。



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

$ pre $ g $ git push -force-with-lease origin master master

- force-with-lease 只有当您的本地分支机构与您推送的分支机构保持最新状态时,才能推动成功。 (这可以防止意外地覆盖你不知道的提交。)我强烈建议使用 with-lease 变体,而不是旧的 - 强制参数,这是不安全的。


I'm trying to push commits to a remote and getting this error message:

$  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.

I think I've got in a muddle somewhere by pushing multiple local branches to this single remote branch and I'd like to basically clear out what's on the server and push a whole branch from fresh. Is this possible, or is there a better way to fix this error?

Ps. this remote branch is hosted on Fortrabbit so I've not got full access to the server to simply delete the branch and create a new one because Fortrabbit's deployment mechanism is based on Git.

解决方案

I'd like to basically clear out what's on the server and push a whole branch from fresh.

This likely means a force push. Note that force pushing is generally not a safe thing to do, and should especially be avoided when pushing to a shared source code repository like GitHub. But in this situation, where you are pushing to update a PaaS server, it is likely okay.

You might want to visualize your branches graphically using gitk, git log --all --graph --decorate, or some other tool before force pushing, just to make sure that everything looks as you expect.

To force push your local master branch to your origin remote's master branch, run

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

The --force-with-lease argument will cause the force push to succeed only if your local branch is up to date with respect to the one you're pushing to. (This prevents accidental overwriting of commits you don't know about.) I strongly advise using the with-lease variant whenever possible instead of the old --force argument, which is less safe.

这篇关于如何解决Git中的问题:“更新被拒绝是因为推送的分支提示位于其远程对方后面”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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