gitosis 和 git clone 问题

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

gitosis and git clone problem

gitversion-controlgitosis

提问by Alexey Poimtsev

I have installed gitosis, but i have strange thing when i'm working with repos. In config i have

我已经安装了 gitosis,但是当我使用 repos 时我遇到了奇怪的事情。在配置中我有

[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = me@server me@laptop

[group prj1]
writable = prj1
members = me@laptop

and in /home/git/repositories i have created directory prj1.git with empty git repo.

在 /home/git/repositories 中,我创建了目录 prj1.git,其中包含空的 git repo。

i can work with gitosis-admin from server and laptop without problems, but when i'm trying to git cloneprj1 on my laptop i see

我可以在服务器和笔记本电脑上使用 gitosis-admin 没有问题,但是当我尝试在笔记本电脑上git cloneprj1 时,我看到

$ git clone git@server:prj1.git
Initialized empty Git repository in /Users/alec/temp/prj1/.git/
fatal: no matching remote head

ok, lets push prj1 from laptop to server:

好的,让我们将 prj1 从笔记本电脑推送到服务器:

$ git push origin master:refs/heads/master
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

Whats wrong?

怎么了?

回答by VonC

Would the following, done on your laptop, solve this issue?
Instead of a git clone:

在您的笔记本电脑上完成以下操作是否可以解决此问题?
而不是 git 克隆:

  mkdir prj1
  cd prj1
  git init
  touch README
  git add .
  git commit -m "Added blank readme"
  git remote add origin git@server:prj1.git
  git push origin master

ebneteradds in the comment:

ebneter在评论中补充道:

You might mention that the reason this works is that you can't clone an empty repo.
(As my users regularly discover...

您可能会提到这样做的原因是您无法克隆空的 repo
(因为我的用户经常发现......

And that reminds the OP question:

这提醒了 OP 问题:

... and in /home/git/repositoriesI have created directory prj1.git with empty git repo

...并在/home/git/repositories我创建目录 prj1.git 与空 git repo

which is not ideal right there.
This SO questionmentions the issue of cloning an empty repo:

这在那里并不理想。
这个SO 问题提到了克隆空仓库的问题:

In other words, don't attempt to clone the empty repo, but rather after creating it, push to it a simple repo containing one innocuous file. Then it is no longer empty and can be cloned.

换句话说,不要试图克隆空的 repo,而是在创建它之后,将一个包含一个无害文件的简单 repo 推送给它。然后它不再是空的,可以被克隆。



Since then, Chris Johnsencomments:

从那时起,克里斯约翰森评论道:

Any Git later than 1.6.2

任何 1.6.2 之后的 Git

(so actually since March 2009)

(所以实际上自 2009 年 3 月以来)

can “clone” empty repositories.
(scare quotes because it really just amounts normal initialization plus setting up a remote, and creating a tracking configuration for the presumed, eventual master branch).

可以“克隆”空的存储库。
(吓人的报价,因为它实际上只是正常的初始化加上设置远程,并为假定的最终主分支创建跟踪配置)。

回答by Naufal

I had the same problem which persisted even after following the steps in Answer 1.

即使按照答案 1 中的步骤操作,我也遇到了同样的问题。

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

solved it for me. Apparently older versions of setuptools can make the post-update hook non-executable. Refer this page.

为我解决了。显然,旧版本的 setuptools 会使 post-update 钩子无法执行。请参阅此页面

回答by stwienert

I ran into the same message, after I want to push to a new repository:

在我想推送到新存储库后,我遇到了相同的消息:

git push -u origin master
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

The reason was that I had 2 same ssh pub-keys (same key, different name) in gitosis-admin/keydir.

原因是我在 gitosis-admin/keydir 中有 2 个相同的 ssh 公钥(相同的密钥,不同的名称)。

After deleting one of it, I can push to new repositories

删除其中之一后,我可以推送到新的存储库

回答by marie

Had the same problem, the reason was that I edited gitosis.conf on my local and did not commit it to server.

有同样的问题,原因是我在本地编辑了 gitosis.conf 并且没有将其提交到服务器。

回答by lkraav

In my case, ssh client picked the wrong private key from ~/.ssh.

就我而言,ssh 客户端从 ~/.ssh 中选择了错误的私钥。

[gitosis] loglevel = DEBUG helped seeing that the wrong user was being logged in.

[gitosis] loglevel = DEBUG 有助于看到错误的用户正在登录。