我已经在虚拟机上运行了gitlabhq rails服务器,遵循本教程https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md中的1-6步,并启动rails服务器,执行命令sudo -u git -H bundle exec rails s -e production。之后,我创建了用户,使用管理工具,并在此用户下创建了新项目。然后,我试图像往常一样将现有项目推到这个回购。但在最后一步,git push origin master失败,并出现错误

[远程拒绝]master -> master(预接收钩子拒绝)

额外的信息:

1)我还没有通过电子邮件激活链接激活用户(项目所有者),因为我还没有在服务器端配置post服务,我没有找到如何在本手册中做到这一点的说明。

2) Gitlab服务器生成提示如何推送项目到repo,没有repositories/ in路径。我的意思是它生成git@mygitlabhost:user/repo。Git代替git@mygitlabhost:repositories/user/repo。Git是正确的。

3)当我试图调试它时,我在服务器上的repo中打开了预接收脚本,并尝试输出变量(有3个):refs = ARGF。read, key_id = ENV['GL_ID'] and repo_path = Dir。PWD和发现,key_id总是空的。也许问题就在这里……如果是这样,请给我建议如何解决。谢谢


当前回答

我已经按照heroku日志img https://devcenter.heroku.com/articles/buildpacks#detection-failure的指示(使用cmd: heroku日志->显示您的错误) 然后执行cmd: "heroku buildpacks:clear"。最后,它对我有用!

其他回答

这对我很管用。

在最新版本的GitLab中,你可以在下面找到它:

你的GitLab项目>设置>存储库>受保护的分支 一个或两个设置(允许合并/推送)设置为:开发人员+维护者或使人成为维护者。

https://gitlab.com/gitlab-org/gitlab-recipes/-/issues/27

GitLab默认将主分支标记为受保护(请参阅https://about.gitlab.com/2014/11/26/keeping-your-code-protected/ why中的保护代码部分)。如果你的情况是这样,那么下面的方法会有所帮助:

打开你的项目> Settings > Repository,进入“Protected branches”,在列表中找到“master”分支,然后点击“Unprotect”再试一次。

通过https://gitlab.com/gitlab-com/support-forum/issues/40

8.11及以上版本的操作指南请访问:https://docs.gitlab.com/ee/user/project/protected_branches.html#restricting-push-and-merge-access-to-certain-users

在我的情况下,我的团队领导创建了一个repo(repo是空的),并分配我作为开发人员,所以当我直接推到代码以掌握我所面临的错误![远程拒绝]主->主(预接收钩子拒绝)所以它是如何修复的,他分配给我作为维护者,这样我就可以直接把代码推给主。

我在使用BitBucket时偶然发现了同样的错误。我有一个本地的Git回购,我想在线备份,所以我从我的BitBucket帐户创建了一个新的存储库(使用web界面)。

运行git后远程添加origin git@bitbucket.org:StatMarianne/<a private repo>。我运行git push origin master没有任何效果(我通常不会在git push中使用-u选项,因为我不介意在推拉时输入完整的repo和分支名称)。

错误如下:

remote: You're not allowed to write to this repository.
To bitbucket.org:StatMarianne/<a private repo>.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@bitbucket.org:StatMarianne/<a private repo>.git'

但是当我运行git push -u origin master(严格按照BitBucket的指示)时,我的本地分支确实被成功推送了。

我发现这很令人惊讶,因为-u(——set-upstream)应该只“添加上游(跟踪)引用…”不管怎样。

对我来说,发生这种情况是因为之前的未决意见不符合某些标准。经过下面的命令,它为我工作 git重置——硬提交 (成功提交的commit id先于不成功提交的commit id)