git push 被拒绝:错误:无法推送一些引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9832348/
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
git push rejected: error: failed to push some refs
提问by Eric
I know people have asked similar questions, but I believe the causes of their problems to be different. I did a hard reset because I had messed up my code pretty bad
我知道人们问过类似的问题,但我相信他们的问题的原因是不同的。我做了一个硬重置,因为我把我的代码搞砸了
git reset --hard 41651df8fc9
I've made quite some changes, I've made some commits and now that I'm trying to push all these commits into the server I get the following error:
我做了很多改变,我做了一些提交,现在我试图将所有这些提交推送到服务器中,我收到以下错误:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]'
Git suggests to do a git pull and that's what other people have suggested to other users. However, I believe that a git pull will merge my current code with the code that I don't want anymore (head revision). How can I do a push and forget about the version/revisions ahead of me?
Git 建议做一个 git pull ,这就是其他人向其他用户建议的。但是,我相信 git pull 会将我当前的代码与我不再需要的代码(头部修订)合并。我怎样才能推动并忘记我面前的版本/修订?
回答by blueshift
git push -f
if you have permission, but that will screw up anyone else who pulls from that repo, so be careful.
git push -f
如果您有许可,但这会搞砸从该回购中提取的任何其他人,所以要小心。
If that is denied, and you have access to the server, as canzar says below, you can allow this on the server with
如果这被拒绝,并且您可以访问服务器,如下面的 canzar 所述,您可以在服务器上允许此操作
git config receive.denyNonFastForwards false
回答by ouah
If you are the only the person working on the project, what you can do is:
如果您是该项目的唯一工作人员,您可以做的是:
git checkout master
git push origin +HEAD
This will set the tip of origin/master to the same commit as master (and so delete the commits between 41651df and origin/master)
这会将 origin/master 的提示设置为与 master 相同的提交(因此删除 41651df 和 origin/master 之间的提交)
回答by Robin Wieruch
Just do
做就是了
git pull origin [branch]
and then you should be able to push.
然后你应该能够推动。
If you have commits on your own and didn't push it the branch yet, try
如果您自己提交了并且还没有将其推送到分支,请尝试
git pull --rebase origin [branch]
and then you should be able to push.
然后你应该能够推动。
回答by manojlds
'remote: error: denying non-fast-forward refs/heads/master (you should pull first)'
“远程:错误:拒绝非快进参考/头/主(你应该先拉)”
That message suggests that there is a hook on the server that is rejecting fast forward pushes. Yes, it is usually not recommended and is a good guard, but since you are the only person using it and you want to do the force push, contact the administrator of the repo to allow to do the non-fastforward push by temporarily removing the hook or giving you the permission in the hook to do so.
该消息表明服务器上有一个拒绝快进推送的钩子。是的,它通常不被推荐并且是一个很好的保护,但是由于您是唯一使用它的人并且您想要进行强制推送,请联系 repo 的管理员以允许通过暂时删除hook 或在 hook 中授予您这样做的权限。
回答by Pritam Banerjee
What I did to solve the problem was:
我为解决问题所做的是:
git pull origin [branch]
git push origin [branch]
Also make sure that you are pointing to the right branch by running:
还要确保您通过运行指向正确的分支:
git remote set-url origin [url]
回答by Sultan Ali
for me following worked, just ran these command one by one
对于我以下工作,只需一一运行这些命令
git pull -r origin master
git push -f origin your_branch
git pull -r origin master
git push -f origin your_branch
回答by Aniket J kamble
I did the following steps to resolve the issue. On the branch which was giving me the error:
我做了以下步骤来解决这个问题。在给我错误的分支上:
git pull origin [branch-name]<current branch>
- After pulling, got some merge issues, solved them, pushed the changes to the same branch.
- Created the Pull request with the pushed branch... tada, My changes were reflecting, all of them.
git pull origin [branch-name]<current branch>
- 拉动后,遇到了一些合并问题,解决了它们,将更改推送到同一分支。
- 使用推送的分支创建了拉取请求... tada,我的更改正在反映,所有这些。