我已经在虚拟机上运行了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总是空的。也许问题就在这里……如果是这样,请给我建议如何解决。谢谢


当前回答

以下是我本地机器中解决的问题:

A.首先,确保您使用正确的登录细节连接到Bitbucket服务器(即。您的用户名/密码/SSH密钥)

B. Then, ensure that the name/email address is correctly set in your local Git configuration: Set your local Git configuration for the account that you are trying to push under (the check asserts that you are the person who committed the files) * Note that this is case sensitive, both for name and email address * It is also space sensitive - some company accounts have extra spaces/characters in their name eg. "Contractor/ space space(LDN)".  You must include the same number of spaces in your configuration as on Bitbucket Server.  Check this in Notepad if stuck.

C.如果您使用了错误的帐户,只需切换您的帐户凭据(用户名/密码/SSH密钥),然后重试。

D.否则,如果您的本地配置不正确,您将需要修改它

对于MAC

打开一个TextEdit。应用~ / .gitconfig

注意:您必须修复您试图推送的旧提交。

修改上次提交: > git commit - modify -reset-author    <save并退出打开的提交文件文本编辑器,如果Vim then :wq保存退出> 尝试重新推动你的提交: > git push

其他回答

如果你正面临这样的问题

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

这是因为master是受保护的,你可以做2步

要移除保护,请遵循以下步骤-

进入项目设置。 单击Repository选项卡。 打开受保护的分支。 找到你的主分支并单击Unprotect。

否则

我们可以从主分支切换到主分支

Git checkout -b main git分支-D master Git push heroku main

黑客快乐! !

我也遇到过同样的问题,这是因为我直接在主分支中推送我的代码,而我没有这个权限。所以我把我的代码推到一个新的分支中,在那之后,我创建了一个pull请求来合并master。

这对我很管用。

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

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

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

你需要添加你的ssh密钥到你的git帐户,如果它抛出错误,然后删除之前的ssh密钥,并创建一个新的ssh密钥,然后添加。

这是因为主分支受到保护,以下是清除此错误的步骤。

在你的主分支中创建一个分支git checkout -b new-branch-name 推送新的分支git Push——set-upstream origin new-branch-name 现在远程地将分支合并到主分支。 一旦合并,重置本地主分支git重置-soft HEAD~1 最后git拉