尝试推送时出现 Git 错误——预接收钩子被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7986139/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:13:35  来源:igfitidea点击:

Git error when trying to push -- pre-receive hook declined

git

提问by Dave

When I try and push a change I've commited, I get the following error ...

当我尝试推送我已提交的更改时,出现以下错误...

git.exe push -v --progress  "origin" iteration1:iteration1

remote: *********************************************************************
To ssh://git@mycogit/cit_pplus.git
! [remote rejected] iteration1 -> iteration1 (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@mycogit/cit_pplus.git'

What's going on?

这是怎么回事?

采纳答案by Alexander Gladysh

You should ask whoever maintains the repo at git@mycogit/cit_pplus.git.

您应该询问谁在git@mycogit/cit_pplus.git.

Your commits were rejected by the pre-receivehookof that repo (that's a user-configurable script that is intended to analyze incoming commits and decide if they are good enough to be accepted into the repo).

您的提交被该 repo的pre-receive钩子拒绝(这是一个用户可配置的脚本,旨在分析传入的提交并确定它们是否足以被接受到 repo 中)。

It is also a good idea to ask that person to update the hook, so it would print the reasons for the rejection.

让那个人更新钩子也是一个好主意,这样它就会打印出拒绝的原因。

If the maintainer is you yourself, then it looks like you've got a problem with your setup on the server-side. Please share more information then.

如果维护者是您自己,那么您在服务器端的设置似乎有问题。那么请分享更多信息。

回答by ThiefMaster

I'd bet that you are trying a non-fast-forward push and the hook blocks it. If that's the case, simply run git pull --rebasebefore pushing to rebase your local changes on the newest codebase.

我敢打赌,您正在尝试非快进推动并且钩子阻止了它。如果是这种情况,只需git pull --rebase在推送以根据最新代码库重新设置本地更改之前运行。

回答by ozkary

File size is important. There is a limit of ~120MB for a single file. In my case, .gitignore using Visual Studio had the file listed, but the file was still committed. When using the git cli, we can get more detail information about the error.

文件大小很重要。单个文件的限制为 ~120MB。就我而言,使用 Visual Studio 的 .gitignore 列出了该文件,但该文件仍被提交。使用 git cli 时,我们可以获得有关错误的更多详细信息。

pre-receive hook declined was as a result of the big file. Basically validating the push.

预接收钩拒绝是由于大文件。基本上验证推送。

To resolve it, I removed the last commit using:

为了解决它,我使用以下命令删除了最后一次提交:

git reset --soft HEAD~1

I then excluded the file from the commit.

然后我从提交中排除了该文件。

Note: Use HEAD~N to go back to N number of previous commits. (i.e. 3, 4) Always use the --soft switch to maintain changes in the folder

注意:使用 HEAD~N 返回到之前提交的 N 次。(即3、4)始终使用--soft开关来维护文件夹中的更改

hope it helps.

希望能帮助到你。

回答by flahsy

This may be because you didn't have the access right to push a commit to a branch such as master. You can ask the maintainer to give you the right to push commits.

这可能是因为您没有将提交推送到分支的访问权限,例如master. 您可以要求维护者授予您推送提交的权利。

回答by Dave de Jong

In my case I got this message because the branch was marked as 'Protected' in GitLab.

就我而言,我收到此消息是因为该分支在 GitLab 中被标记为“受保护”。

回答by Thomm

I got this message when the GitLab server was undergoing some changes. The next day pushing worked fine. Anyways, as others pointed out, check with your maintainer to be sure.

当 GitLab 服务器发生一些变化时,我收到了这条消息。第二天推送工作正常。无论如何,正如其他人指出的那样,请与您的维护者确认。

回答by serup

I had this issue when trying to merge changes with file size greater than what remote repository allowed (in my case it was GitHub)

我在尝试合并文件大小大于远程存储库允许的更改时遇到了这个问题(在我的例子中是 GitHub)

回答by shapiro yaacov

I encountered this same issue.
What solved it for me was to switch to another branch and then back to the original one.

我遇到了同样的问题。
为我解决的是切换到另一个分支,然后回到原来的分支。

Not sure what the underline cause was, but this fixed it.

不确定下划线的原因是什么,但这修复了它。

回答by diman82

Bitbucket: Check for Branch permissions in Settings (it may be on 'Deny all'). If that doesn't work, simply clone your branch to a new local branch, push the changes to the remote (a new remote branch will be created), and create a PR.

Bitbucket:检查设置中的分支权限(它可能位于“拒绝全部”)。如果这不起作用,只需将您的分支克隆到一个新的本地分支,将更改推送到远程(将创建一个新的远程分支),然后创建一个 PR。

回答by Sandra Pavan

I faced the same error, upon checking I had a developer access and couldn't publish a new branch. Adding higher access rights resolved this issue.(Gitlab)

我遇到了同样的错误,检查后我有开发人员访问权限并且无法发布新分支。添加更高的访问权限解决了这个问题。(Gitlab)