推送到 github 时出错 - 更新被拒绝,因为推送的分支提示在其远程后面 [英] Getting an error pushing to github - Updates were rejected because a pushed branch tip is behind its remote

查看:35
本文介绍了推送到 github 时出错 - 更新被拒绝,因为推送的分支提示在其远程后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在推送到不同的 heroku 遥控器时遇到问题.

I am having a problem pushing to a different heroku remote.

为了检查自己,我将整个项目目录重命名为 _backup 然后:

To check myself I renamed my entire project directory to _backup and then:

git clone account/repo_name

git remote add repo2 git@heroku.com:repo2.git

git push repo2 branch_abc:master

但我仍然得到

hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我已经尝试了几个 SO 问题和答案,但对我不起作用,无论如何仍然出现错误.

I have tried several SO questions and answers but not worked for me, still getting the error regardless.

推荐答案

如果您不关心当前 repo2 中的内容并且有信心完全覆盖它,那么您可以使用:

$ git push -f git@heroku.com:<heroku repo name>.git

请记住,push -f 可以清除其他开发人员的更改,如果它们是自您上次从存储库中撤出后发布的...所以请务必谨慎使用多开发团队!
在这种情况下,heroku 始终位于下游,而 github 是管理和维护代码的地方,因此这使得 Heroku 上的 push -f 成为比其他情况下更安全的选择.

Remember though that push -f can wipe out other developers changes if they were posted since you last pulled from the repo... so always use with extreme caution on multi-developer teams!
In this case heroku is always downstream and github is where the code is managed and maintained so this makes push -f on heroku a safer option that it would otherwise be.

这篇关于推送到 github 时出错 - 更新被拒绝,因为推送的分支提示在其远程后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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