git 推送到 github 时出错 - 更新被拒绝,因为推送的分支提示在其远程后面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14609263/
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
Getting an error pushing to github - Updates were rejected because a pushed branch tip is behind its remote
提问by Michael Durrant
I am having a problem pushing to a different heroku remote.
我在推送到不同的 heroku 遥控器时遇到问题。
To check myself I renamed my entire project directory to _backup and then:
为了检查自己,我将整个项目目录重命名为 _backup,然后:
git clone account/repo_name
git remote add repo2 [email protected]:repo2.git
git push repo2 branch_abc:master
But I am still getting
但我仍然得到
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.
I have tried several SO questions and answers but not worked for me, still getting the error regardless.
我已经尝试了几个 SO 问题和答案,但对我不起作用,无论如何仍然出现错误。
回答by uday
If you don't care about what's currently in repo2 and are confident that totally overwriting it is okthen you can use:
如果您不关心当前在 repo2 中的内容并且确信完全覆盖它是可以的,那么您可以使用:
$ git push -f [email protected]:<heroku repo name>.git
Remember though that push -f
can wipe out other developers changesif 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.
请记住,如果自您上次从 repo 中撤出后发布的push -f
其他开发人员更改,则可能会消除其他开发人员的更改……因此,对于多开发人员团队,请务必格外小心!
在这种情况下,heroku 始终位于下游,而 github 是管理和维护代码的地方,因此这使得push -f
heroku 成为比其他情况更安全的选择。
回答by Michael James Kali Galarnyk
I am always a big fan of using git pull --rebase and then git push origin master . A couple of the places I have worked since a lot of places do not allow a push -f (especially places that use bitbucket).
我一直是使用 git pull --rebase 然后使用 git push origin master 的忠实粉丝。因为很多地方都不允许 push -f(尤其是使用 bitbucket 的地方),所以我工作过的几个地方。
git pull?--rebase
git push origin master
The rebase will apply your changes after those already to the remote (online website). This video literally goes over your exact issue and solves it using git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s
rebase 将在那些已经应用于远程(在线网站)的更改之后应用您的更改。该视频从字面上详细介绍了您的确切问题并使用 git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s解决它
回答by guest101
If you pull the other repo first:
如果您先拉另一个回购:
git pull repo2
git pull repo2
This will merge in the other repos's changes which you can add and commit.
这将合并到您可以添加和提交的其他存储库的更改中。
Then you can push the repo back.
然后你可以将回购推回去。