git 错误:钩子在推送分支时拒绝更新 refs/heads/external_pub
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16690785/
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
error: hook declined to update refs/heads/external_pub while pushing a branch
提问by TDHM
Currently, I'm working on 'external_pub' branch. I made few changes in one file, added it, committed & then tried to push:
目前,我正在“external_pub”分支上工作。我在一个文件中做了一些更改,添加了它,提交了然后尝试推送:
git push origin external_pub
But this was resulted into an error:
但这导致了错误:
remote: error: hook declined to update refs/heads/external_pub
To ssh://XXX/testing.git
! [remote rejected] external_pub -> external_pub (hook declined)
error: failed to push some refs to 'ssh://XXX/testing.git'
Then I tried to push branch without any change to see what happens(just for isolating issue). I did following:
然后我尝试在没有任何更改的情况下推送分支以查看会发生什么(仅用于隔离问题)。我做了以下:
git reset --hard <commit_id> (to reset to last working sha commit)
git status
Above command showed:
上面的命令显示:
# On branch external_pub
# Your branch is ahead of 'development' by 5 commits.
#
nothing to commit (working directory clean)
Then
然后
git pull origin external_pub
It showed: your branch is already upto date
它显示:您的分支已经是最新的
Then
然后
git push origin external_pub
This time also, it showed the same error as above. Could you please help me to solve this?
这一次,它也显示了与上面相同的错误。你能帮我解决这个问题吗?
回答by 1615903
There's a git hookon the server that rejected the push. Quoting:
服务器上有一个拒绝推送的git 钩子。引用:
These scripts run before and after pushes to the server. The pre hooks can exit non-zero at any time to reject the push as well as print an error message back to the client; you can set up a push policy that's as complex as you wish.
这些脚本在推送到服务器之前和之后运行。pre hooks 可以随时退出非零以拒绝推送并将错误消息打印回客户端;您可以设置任意复杂的推送策略。
To find out why, you need to know what the hook does. Hooks are stored in hooks
folder inside the git folder (on the remote end) - find the pre-receivehook or updatehook and examine that.
要找出原因,您需要知道钩子的作用。钩子存储在hooks
git 文件夹内的文件夹中(在远程端) - 找到预接收钩子或更新钩子并检查它。
回答by user68991
In OSX its usually caused by missing GEM's between brew ruby install and Apple ruby 2.0 (default).
在 OSX 中,它通常是由于 brew ruby install 和 Apple ruby 2.0(默认)之间缺少 GEM 造成的。
An include 'require json/ext/parser' or similar add-on is not found and exceptions at the require point.
未找到 include 'require json/ext/parser' 或类似的附加组件,并且在 require 点出现异常。
回答by Raj Kumar Mishra
I resolved this issue. Normally I use VSTSID (Visual Studio Team Services) in message while committing code. Use the steps below:
我解决了这个问题。通常我在提交代码时在消息中使用 VSTSID(Visual Studio Team Services)。使用以下步骤:
git commit --amend (now its time to edit your commit message)
git commit -m "vs[your_vsts_id]-your_commit_message>" then press
i(keyboard button)
Esc(keyboard button)
:wq(to save)
git commit --amend(现在是编辑提交信息的时候了)
git commit -m "vs[your_vsts_id]-your_commit_message>" 然后按
i(键盘按钮)
Esc(键盘按钮)
:wq(保存)
After that you will be able to push(git push).
之后,您将能够推送(git push)。
If you still facing the issue, type git reset --soft HEAD^
in git bash. Now you can see all your files in green color. It means, files are again ready for commit. Depending on your requirement, you can use reset (git reset
) command as well.
如果您仍然遇到问题,请输入git reset --soft HEAD^
git bash。现在您可以看到所有文件都显示为绿色。这意味着,文件再次准备好提交。根据您的要求,您也可以使用 reset ( git reset
) 命令。
回答by Julio Nobre
In case you are using Redmine Git Hosting, check your projet permissions Managerrole has been assigned to the user that is trying to rewrite his/her git's tracking references.
如果您使用的是Redmine Git Hosting,请检查您的项目权限管理器角色是否已分配给尝试重写其 git 跟踪引用的用户。
Please note that I am assuming you are aware on git push -forceimpact on the other users that may be sharing the same remote branch. For further details, check this article
请注意,我假设您知道git push -force对可能共享同一远程分支的其他用户的影响。有关更多详细信息,请查看这篇文章