【发布时间】:2011-08-20 15:09:13
【问题描述】:
【问题讨论】:
【问题讨论】:
将此添加到您的 httpd.conf(假设 /srv/git 包含您的存储库)
<Directory "/usr/lib/git-core*">
Order allow,deny
Allow from all
</Directory>
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
然后确保 apache 可以写入您的存储库目录(从 repo 内部运行这里 http 是您的 apache 用户)
chown -R http .
在您在服务器上创建的存储库中打开 .git/config 并添加以下内容
[http]
receivepack = true
最后在仓库根目录运行
git config --bool core.bare true
或者,如果您想要服务器上可用的文件(用于网站或其他),则忽略上述命令并使用此编辑 .git/config
[receive]
denyCurrentBranch = false
然后当你想更新目录时在服务器上运行它(必须有更好的方法所以请告诉我)
git reset --hard
【讨论】:
请注意,从 git 1.6.6 开始,DAV 比新的“smart-http”支持慢得多。新方法允许一次传输整个包,而不是作为单个文件。
下面的设置消除了在每个 repo (http.receivepack) 中进行自定义配置的需要,或者不需要硬重置。只需使用
制作每个新的 re[pogit --bare init --shared
您还可以使用 gitweb 在同一位置提供可浏览的 URL。
注意:由于访问是由 apache 控制的,因此您可以将任何 Auth 要求(htaccess 或 ldap 等)添加到每个存储库的设置中。
只需新建一个 git_support.conf 文件,并将其包含在 apache 中(在 httpd.conf 中添加 include 语句)
#
# Basic setup for git-http-backend
#
SetEnv GIT_PROJECT_ROOT /opt/git_repos
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER #IMportant !!! This could be your problem if missing
<Directory /opt/git> # both http_backend and gitweb should be somewhere under here
AllowOverride None
Options +ExecCGI -Includes #Important! Lets apache execute the script!
Order allow,deny
Allow from all
</Directory>
# This pattern matches git operations and passes them to http-backend
ScriptAliasMatch \
"(?x)^/git/(.*/(HEAD | \
info/refs | \
objects/(info/[^/]+ | \
[0-9a-f]{2}/[0-9a-f]{38} | \
pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
git-(upload|receive)-pack))$" \
/opt/git/libexec/git-core/git-http-backend/$1
# Anything not matched above goes to displayable gitweb interface
ScriptAlias /git /opt/git/cgi-bin/gitweb.cgi/
结果是推/拉的能力:
me@machine /tmp/eddies $ git pull
Already up-to-date.
me@machine /tmp/eddies $ touch changedFile
me@machine /tmp/eddies $ git add .
me@machine /tmp/eddies $ git commit -am"commiting change"
[master ca7f6ed] commiting change
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 changedFile
me@machine /tmp/eddies $ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 239 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To http://mysecretdomain.com/git/eddies
0f626a9..ca7f6ed master -> master
您可以在线浏览这些更改..
来源: http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README
【讨论】:
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER 行。我花了一个小时在谷歌上搜索为什么我在配置其他所有内容时得到 403。
只是不要在您的 Apache 配置中添加任何 AuthType(所以不要使用 LocationMatch 或 Location 元素)。
如果您没有 AuthType ,这意味着您的 Apache 将简单地将您的 git 请求传递给 cgi 程序 git-http-backend。
所以在这种情况下不会进行身份验证:匿名推送将是可能的。
【讨论】:
AuthType,但我仍然收到此消息 error: Cannot access URL http://localhost/git/test/, return code 22 来自该位置的 git clone 工作正常
<LocationMatch > 元素及其 Options +ExecCGI,但没有其他内容(与身份验证相关),这应该有效。关键是要确保CGI执行完毕,否则依赖WEBDAV,会触发错误22。