为什么 git-daemon 不为我的存储库提供服务?

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

Why won't git-daemon serve my repository?

gitgit-daemon

提问by Yazz.com

I set up .gitin a directory on my local machine. I then run:

.git在本地机器上的一个目录中设置。然后我运行:

mkdir a
cd a
git init
git daemon

When I attempt to clone the repository in a, I get the following error:

当我尝试在 中克隆存储库时a,出现以下错误:

mkdir b
cd b
git clone git://127.0.0.1
Initialized empty Git repository in /b/127.0.0.1/.git/
fatal: The remote end hung up unexpectedly

How can I clone my repository over the git protocol?

如何通过 git 协议克隆我的存储库?

回答by Greg Bacon

You need to let git-daemonknow it may export your repository:

您需要git-daemon知道它可能会导出您的存储库:

$ git init --bare /tmp/my-repo.git
Initialized empty Git repository in /tmp/my-repo.git/

$ git daemon --verbose --base-path=/tmp --export-all /tmp/my-repo.git &

$ git clone git://`hostname`/my-repo.git
Initialized empty Git repository in /tmp/my-repo/.git/
warning: You appear to have cloned an empty repository.

A far better way is to run it from xinetd. Create and tweak /etc/xinetd.d/gitalong the lines of

更好的方法是从xinetd. 创建和调整/etc/xinetd.d/git沿线

# description: The git server offers access to git repositories
service git
{
        disable = no
        type            = UNLISTED
        port            = 9418
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/local/bin/git
        server_args     = daemon --inetd --export-all --base-path=/pub/scm
        log_on_failure  += USERID
}

Don't forget to sudo killall -HUP xinetd. Now, all git repositories beneath /pub/scmwill be available to anyone who asks.

不要忘记sudo killall -HUP xinetd。现在,/pub/scm任何人都可以使用下面的所有 git 存储库。

回答by Fabian Jakobs

You either have to put an empty file called git-daemon-export-okinto the repository or start git daemonwith the --export-alloption.

您要么必须将一个空文件git-daemon-export-ok放入存储库中,要么从git daemon--export-all选项开始。

Quote from the git-daemon man page:

引用来自 git-daemon手册页

It verifies that the directory has the magic file "git-daemon-export-ok", and it will refuse to export any git directory that hasn't explicitly been marked for export this way (unless the --export-all parameter is specified). If you pass some directory paths as git daemon arguments, you can further restrict the offers to a whitelist comprising of those.

它验证目录是否有魔法文件“git-daemon-export-ok”,并且它会拒绝导出任何没有明确标记为导出的git目录(除非指定了--export-all参数) )。如果您将一些目录路径作为 git daemon 参数传递,您可以进一步将优惠限制为包含这些的白名单。