简体   繁体   English

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

[英]Git error when trying to push -- pre-receive hook declined

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?这是怎么回事?

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-receive hook of 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.那么请分享更多信息。

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 --rebase before pushing to rebase your local changes on the newest codebase.如果是这种情况,只需在推送之前运行git pull --rebase即可将本地更改重新设置在最新的代码库上。

File size is important.文件大小很重要。 There is a limit of ~120MB for a single file.单个文件的限制为 ~120MB。 In my case, .gitignore using Visual Studio had the file listed, but the file was still committed.就我而言,使用 Visual Studio 的 .gitignore 列出了该文件,但该文件仍被提交。 When using the git cli, we can get more detail information about the error.使用 git cli 时,我们可以获得有关错误的更多详细信息。

pre-receive hook declined was as a result of the big file. pre-receive hook 被拒绝是由于大文件。 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.注意:使用 HEAD~N 返回 N 次之前的提交。 (ie 3, 4) Always use the --soft switch to maintain changes in the folder (即 3、4)始终使用 --soft 开关来维护文件夹中的更改

hope it helps.希望能帮助到你。

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

This may be because you didn't have the access right to push a commit to a branch such as master .这可能是因为您没有将提交推送到master等分支的访问权限。 You can ask the maintainer to give you the right to push commits.您可以要求维护者授予您推送提交的权利。

in sometimes, because the branch you are pushing has been protected, so you can ask the repository's maintainers to change the protecting status.有时候,因为你推送的分支已经被保护了,所以你可以要求仓库的维护者改变保护状态。 in git-lab , you can find it in在 git-lab 中,您可以在

Settings > Repository > Protected Branches .

:) :)

On my case (Bitbucket), the problem was Rewriting branch history is not allowed restriction.在我的情况下(Bitbucket),问题是Rewriting branch history is not allowed Go to Repository settings -> Branch Permissions edit the selected branch's permissions, and check Allow rewriting branch history转到Repository settings -> Branch Permissions编辑所选分支的权限,并选中Allow rewriting branch history

允许重写分支历史

I got this message when the GitLab server was undergoing some changes.当 GitLab 服务器进行一些更改时,我收到了这条消息。 The next day pushing worked fine.第二天推送效果很好。 Anyways, as others pointed out, check with your maintainer to be sure.无论如何,正如其他人指出的那样,请与您的维护人员确认。

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.不确定下划线的原因是什么,但这解决了它。

尝试合并文件大小大于远程存储库允许的更改时遇到此问题(在我的情况下是 GitHub)

In case it helps someone :如果它可以帮助某人:

I had a blank repo with no master branch to unprotect (in Gitlab) so before running git push -u origin --all我有一个空白仓库,没有要取消保护的主分支(在 Gitlab 中),所以在运行git push -u origin --all之前

  • I had to run git push -u origin master first,我必须先运行git push -u origin master
  • unprotect the master branch temporarily暂时解除对 master 分支的保护
  • push the rest ( --all & --tags )推送其余部分( --all--tags

Bitbucket : Check for Branch permissions in Settings (it may be on 'Deny all'). Bitbucket :检查设置中的分支权限(可能在“全部拒绝”上)。 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.如果这不起作用,只需将您的分支克隆到新的本地分支,将更改推送到远程(将创建一个新的远程分支),然后创建一个 PR。

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)

I got this error with GitHub gist.我在 GitHub gist 上遇到了这个错误。 I was trying to push a commit with files in sub-directories.我试图用子目录中的文件推送提交。 Turned out gist can only have files in root directory.原来 gist 只能在根目录中有文件。

删除受保护的分支选项或允许其他角色(如开发人员或管理员)允许这些遇到此错误的用户进行合并和推送。

In my case, we have hooks for commit messages, our server script accepts commits if they have the special format for commit message "<JIRA ID><Message>" .在我的例子中,我们有提交消息的钩子,我们的服务器脚本接受提交,如果它们具有提交消息的特殊格式"<JIRA ID><Message>" It(hook) declines commit if respective Jira ticket does not exist or there are some special symbols in the commit message.如果相应的 Jira 票证不存在或提交消息中有一些特殊符号,则它(挂钩)拒绝提交。 I face this error when I add /, [, > etc. in a commit message, removing those works fine.当我在提交消息中添加 /、[、> 等时,我遇到了这个错误,删除这些工作正常。

For me Authorization on remote git server solve the problem.对我来说,远程 git 服务器上的授权解决了这个问题。 在此处输入图像描述

I was using GitKraken and we made a local branch, then we merged two remote branches in it and then we tried to push the local branch to origin.我正在使用 GitKraken,我们创建了一个本地分支,然后我们在其中合并了两个远程分支,然后我们尝试将本地分支推送到原点。 It didn't work with the same error message.它不适用于相同的错误消息。

The solution was to create the local branch and push it first to origin and then do the merge.解决方案创建本地分支并首先将其推送到原点,然后进行合并。

In my case I got this error because a branch with the same name already existed.就我而言,我收到此错误是因为已经存在同名的分支。 Deleting this branch off of the git server will fix this.从 git 服务器中删除此分支将解决此问题。

我通过重新生成 SSH 密钥并将其添加到 GitHub 帐户解决了这个问题。

I got this when trying to push to a dokku instance.我在尝试推送到一个 dokku 实例时得到了这个。 Turns out the disk was full on my server.原来我的服务器上的磁盘已满。

Ran: du -f冉: du -f

And result was:结果是:

Filesystem      Size  Used Avail Use% Mounted on
udev            476M     0  476M   0% /dev
tmpfs           100M  4.4M   95M   5% /run
/dev/xvda1      7.8G  7.4G  8.9M 100% /

This is actually happens when YACC is enabled at server side in BitBucket.这实际上是在 BitBucket 的服务器端启用 YACC 时发生的。 YACC is enable for JIRA issue names to be mentioned in the commit message. YACC 允许在提交消息中提及 JIRA 问题名称。 So whenever you commit anything atleast keep your JIRA number into the commit message and then additionally you can add your own message.因此,每当您提交任何内容时,至少将您的 JIRA 编号保留在提交消息中,然后您还可以添加自己的消息。

Issue: "PUSH Failed refs/head/ - pre-receive hook declined"问题:“PUSH Failed refs/head/ - pre-receive hook denied”

I've faced the problem of unable to push my changes to my origin branch and anything to master branch of a particular project repository as the size of that repo was over hard limit of 2GB.我遇到了无法将我的更改推送到我的原始分支以及任何特定项目存储库的主分支的问题,因为该存储库的大小超过了 2GB 的硬限制。 It was throwing the error.它正在抛出错误。 That's because we had pushed the test data unknowingly to bitbucket from other testing branches.那是因为我们在不知不觉中将测试数据从其他测试分支推送到了 bitbucket。

PUSH Failed refs/head/ - pre-receive hook declined PUSH Failed refs/head/ - pre-receive hook 被拒绝

So tried checking is that the same with other project repo's and they weren't having any issues.因此尝试检查其他项目回购是否相同,并且他们没有任何问题。

Fix:使固定:

My colleague noticed that when we cloned the project back locally, the size of the project was 110MB.我的同事注意到,当我们将项目克隆回本地时,项目的大小为 110MB。 So then we started cleaning the branches we merged earlier and active branches which are no more required.因此,我们开始清理我们之前合并的分支和不再需要的活动分支。 Once that cleaning is done for couple of branches we realized the size of the repo went drastically down from 2GB to 120MB.一旦对几个分支进行了清理,我们就意识到 repo 的大小从 2GB 急剧下降到 120MB。 Then we tried to push the changes to my branch and it worked.然后我们尝试将更改推送到我的分支并且它起作用了。

对我来说,错误是该项目没有创建任何分支,而我的角色是开发人员,所以我无法创建任何分支,请求他们给我相关的权限,并且现在一切都井井有条!

A default branch (eg master ) does not yet exist for your remote.您的遥控器尚不存在默认分支(例如master )。 So you first need to create master branch in the git remote server (eg creating a default README.md file) then try to push all your existing local branches using this command:所以你首先需要在 git 远程服务器中创建master分支(例如创建一个默认的README.md文件)然后尝试使用这个命令push所有现有的本地分支:

git push -u origin --all

In my case I had a new repository, pushed a branch ('UCA-46', not 'master'), rebased it, forcely pushed again and got the error.在我的情况下,我有一个新的存储库,推送了一个分支('UCA-46',而不是'master'),重新定位它,再次强制推送并得到错误。 No web-hooks existed.不存在网络挂钩。 I executed git pull --rebase as @ThiefMaster advised, had to rebase again and was able to push the branch.我按照@ThiefMaster的建议执行了git pull --rebase ,不得不再次变基并且能够推送分支。 But that was a strange and difficult way.但这是一种奇怪而困难的方式。

Then I saw Git push error pre-receive hook declined .然后我看到Git push error pre-receive hook denied I found that my branch became protected .我发现我的分支被保护了。 I removed protection and could forcely push again.我移除了保护,可以再次强行推动。

在此处输入图像描述

I got this message while trying to delete a remote branch (git push origin --delete [branch-name]).我在尝试删除远程分支时收到此消息(git push origin --delete [branch-name])。 The problem was that the branch was marked un-deletable in bitbucket.问题是分支在 bitbucket 中被标记为不可删除。

Your commit is not compatible with the repository maintainer's rules, you just need to git reset --hard HEAD ~ 1 in order to delete the last commit.您的提交与存储库维护者的规则不兼容,您只需要git reset --hard HEAD ~ 1即可删除最后一次提交。 After that commitment according to the maintainer's rules is ok之后根据维护者的规则进行承诺就可以了

In my case there was a Committer restriction in a project on Gitlab:就我而言,Gitlab 上的一个项目中存在 Committer 限制:

Users can only push commits to this repository that were committed with one of their own verified emails.用户只能将使用他们自己的已验证电子邮件之一提交的提交推送到此存储库。

Since I also configured SSH on my machine, my global_user_email was updated in the git config file with my machine's address, hence the remote was not allowing to push.由于我还在我的机器上配置了 SSH,因此我的 global_user_email 在 git 配置文件中使用我的机器地址进行了更新,因此远程不允许推送。

You can find this at:您可以在以下位置找到它:

  • Gitlab -> Settings -> Repository -> Push Rules Gitlab -> 设置 -> 存储库 -> 推送规则

Just disable the commit restriction and it will work.只需禁用提交限制,它就会起作用。

This is a rather old question and has many answers already.这是一个相当古老的问题,并且已经有很多答案。 But I would like to share the solution that worked for me while working with bitbucket (no admin rights).但我想分享在使用 bitbucket 时对我有用的解决方案(无管理员权限)。 Most of my colleagues (to the exception of one) did not face any issues.我的大多数同事(除了一个)没有遇到任何问题。 The both of us could suddenly not push to precise branches any longer (I could not figure out the actual reason).我们俩突然无法再推到精确的分支(我无法弄清楚实际原因)。 The solution was:解决方案是:

  1. delete existing pull requests related to the problematic branches,删除与有问题的分支相关的现有拉取请求,
  2. delete the branches on server side,删除服务器端的分支,
  3. re-push from local to remote repo, and,从本地重新推送到远程仓库,并且,
  4. create the pull request again.再次创建拉取请求。

I had a similar issue and it was caused by bcrypt npm package.我有一个类似的问题,它是由 bcrypt npm 包引起的。 I uninstalled bcrypt and instead installed bcryptjs.我卸载了 bcrypt,而是安装了 bcryptjs。

npm install --save bcryptjs && npm uninstall --save bcrypt

It's the exact same API.这是完全相同的 API。 All the code inside app.js remains same except the require call need to be changed to require("bcryptjs"); app.js 中的所有代码都保持不变,除了 require 调用需要更改为require("bcryptjs");

I got the same error ! [remote rejected] ... (pre-receive hook declined)我得到了同样的错误! [remote rejected] ... (pre-receive hook declined) ! [remote rejected] ... (pre-receive hook declined) today. ! [remote rejected] ... (pre-receive hook declined)今天。

It was caused by Bitbucket having a problem .它是由Bitbucket 有问题引起的。 So make sure that your Git Remote is up and running.因此,请确保您的 Git Remote 已启动并正在运行。

The issue that prevented me from pushing was: https://bitbucket.status.atlassian.com/incidents/r8kyb5w606g5阻止我推动的问题是: https ://bitbucket.status.atlassian.com/incidents/r8kyb5w606g5

If in a corporate gitlab/ github and you trying to push changes to a branch/master, Pre-hook could mean that you missed some parameters input into the commit message.如果在公司 gitlab/github 中,您尝试将更改推送到分支/master,则 Pre-hook 可能意味着您错过了提交消息中的一些参数输入。

In my case, along with message i was needed to add bug id, bug url and approver in commit file and then push to branch and place the merge request.在我的情况下,我需要在提交文件中添加错误 ID、错误 url 和批准者,然后推送到分支并放置合并请求。

Hope this helps, as when writing commit message ask your mentor/buddy for th e requirements in a commit message.希望这会有所帮助,就像在编写提交消息时向您的导师/伙伴询问提交消息中的要求一样。

Simple and Quick fix:-简单快速的修复:-

git commit -m "branch_name:added git script" git commit -m "branch_name:添加的 git 脚本"

! [remote rejected] master -> master (pre-receive hook declined) [remote denied] master -> master (pre-receive hook denied)

I spend 2 days on this bug!我在这个错误上花了 2 天时间! After a lot of research, I finally found a solution for this.经过大量研究,我终于找到了解决方案。

  1. Heroku config:set USE_NPM_INSTALL=false
  2. Configured the yarn build pack on Heroku在 Heroku 上配置 yarn build pack
  3. Make sure yarn.lock file is NOT in your .gitignore file确保yarn.lock文件不在您的.gitignore文件中

It will work!它会起作用的!

In my case I manage the project myself but recently upgraded it to the hobbyist tier.就我而言,我自己管理该项目,但最近将其升级为爱好者级别。 In any case checked the logs through herokus browser interface and it had a very clear message about the node version (its an express app) not being defined in the package.json.无论如何,通过 herokus 浏览器界面检查日志,它有一条非常明确的消息,表明 package.json 中没有定义节点版本(它是一个快速应用程序)。 They had a link to a heroku page outlining how to fix it and it worked.他们有一个指向 Heroku 页面的链接,该页面概述了如何修复它并且它有效。

In any case I just added this to my package.json and no further issues!无论如何,我只是将它添加到我的 package.json 中,没有其他问题!

  "engines": {
    "node": "16.x",
    "npm": "6.x"
  },

I checked my node version and npm versions first though just to be clear.为了清楚起见,我首先检查了我的节点版本和 npm 版本。 My node version was 16 but my npm version was 7. I decided to leave the npm defined as 6.x just because it's what was listed on the heroku page.我的节点版本是 16,但我的 npm 版本是 7。我决定将 np​​m 定义为 6.x,只是因为它是 heroku 页面上列出的内容。 Didn't encounter any issues.没有遇到任何问题。

$ node --version

$ npm --version

And here's the link to the heroku help page for this.这是heroku帮助页面的链接。

https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

My issue was file size, trying to migrate a project from gitlab to github, and the error did hint at it for me, directing to this page https://docs.github.com/en/repositories/working-with-files/managing-large-files/moving-a-file-in-your-repository-to-git-large-file-storage我的问题是文件大小,试图将项目从 gitlab 迁移到 github,并且错误确实提示了我,指向此页面https://docs.github.com/en/repositories/working-with-files/管理大文件/在您的存储库中移动文件到 git-large-file-storage

The command used was:使用的命令是:

git lfs migrate import --everything --above=100kb

After this I was able to git push --mirror http:...在此之后,我能够git push --mirror http:...

Step1:步骤1:

git pull --rebase

Step2:第2步:

git reset --soft HEAD~1

Step3:第三步:

git commit -m "your comments here"

Step4:第4步:

git push

This should fix your issue.这应该可以解决您的问题。

In my case, it was jira issue integration under project settings in BITBUCKET.就我而言,这是 BITBUCKET 中项目设置下的 jira 问题集成。 By means, we need to put jira issue associated with it.顺便说一下,我们需要将 jira 问题与之相关联。 I had two options 1) disable jira issue in the commit 2) put jira issue reference to the commit.我有两个选择 1) 在提交中禁用 jira 问题 2) 将 jira 问题引用放到提交中。

In my case, it's because I accidentally added a giant file to my uncommitted push and I could not get rid of it no matter whatever pull or reset or rm I did after.就我而言,这是因为我不小心将一个巨大的文件添加到了我未提交的推送中,并且无论我之后做什么 pull 或 reset 或 rm ,我都无法摆脱它。

my dirty solution but workable solution is to rename the current directory, re-clone the directory to local and reflect the changes manually to the recloned local directory...我的肮脏解决方案但可行的解决方案是重命名当前目录,将目录重新克隆到本地并将更改手动反映到重新克隆的本地目录...

It does not sound good but works...这听起来不太好,但工作...

For me everything was working fine until Bitbucket automatically changed their policy today (April 21, 2020).对我来说,一切都很好,直到今天(2020 年 4 月 21 日)Bitbucket 自动更改了他们的政策。 This happens to align with a new feature recently introduced today called Workspaces , so I suspect it has something to do with that.这恰好与今天最近推出的名为Workspaces的新功能保持一致,所以我怀疑它与此有关。

Workaround : I (as an Admin) followed the instructions to add the email address to Users in the UI (the email you are using can be found git config --list解决方法:我(作为管理员)按照说明将电子邮件地址添加到 UI 中的用户(您使用的电子邮件可以在git config --list中找到

在此处输入图像描述

I had permissions issue, after given the right permissions i was able to push the contents.我有权限问题,在获得正确的权限后,我能够推送内容。 I was pushing a existing project into a new git repo.我正在将现有项目推送到新的 git 存储库中。

You should look at the logs.你应该看看日志。 I just ran into the same error and realized from the logs it was because I had a yarn.lock and package-lock.json我刚刚遇到了同样的错误并从日志中意识到这是因为我有一个 yarn.lock 和 package-lock.json

If you facing an issue related to pre-receive hook declined in git while doing Push.如果您在执行 Push 时遇到与 git 中的 pre-receive hook 相关的问题。 You may have the below reasons:您可能有以下原因:

  1. Maybe your DB backup in your project path app_data is exceeded the 100.00 MB limit of Github.也许您的项目路径 app_data 中的数据库备份超出了 Github 的 100.00 MB 限制。
  2. Check the size of your file if you using it in your project not exceeded the size limit of 10.00MB or any file.如果您在项目中使用的文件不超过 10.00MB 或任何文件的大小限制,请检查文件的大小。

You can resolve this issue by the below steps:您可以通过以下步骤解决此问题:

  1. Just do the zip those files and push again git push -u origin develop只需压缩这些文件并再次推送 git push -u origin develop

Specifying a node.js version can solve the problem like 指定node.js版本可以解决类似的问题

{
  "name": "myapp",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": {
    "node": "10.3.0"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM