Git 和重定向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19434605/
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
Git & redirections
提问by Evert
I've noticed that when a git (html) project page such as this:
我注意到当一个 git (html) 项目页面是这样的:
https://github.com/fruux/sabre-dav
is cloned, in this manner:
以这种方式克隆:
git clone https://github.com/fruux/sabre-dav .
The actual resulting remote url, as listed with git remote -v
is a url such as this:
实际生成的远程 url,如所列,git remote -v
是一个如下所示的 url:
origin [email protected]:foo/sabre-dav.git
Presumably because I have push access.
大概是因为我有推送访问权限。
So this made me wonder whether it's possible to redirect any given project url to a git repository. If I for instance own http://myosproject.example.org
, is it possible to allow git clone http://myosproject.example.org
and have it actually redirect somehow to a github project instead.
所以这让我想知道是否可以将任何给定的项目 url 重定向到 git 存储库。例如http://myosproject.example.org
,如果我拥有,是否可以允许git clone http://myosproject.example.org
并让它实际上以某种方式重定向到 github 项目。
采纳答案by Tippa Raj
As long as the bare git (the .git
folder) is in the web servers DocumentRoot
, and you set up a specific post-update
hook, it will work.
只要裸 git(.git
文件夹)在 web 服务器中DocumentRoot
,并且你设置了一个特定的post-update
钩子,它就会工作。
See this book chapter for more on this
To map your own domain name to a github URL
, I think you just need to define an A
record (if you know the IP address) or a CNAME
record (if you only know the domain name) in your DNS
为了你自己的域名映射到一个github URL
,我觉得你只需要定义一个A
记录(如果你知道IP地址),或CNAME
在记录(如果你只知道域名)的DNS
It may also be possible to configure a reverse proxy in your web server to pass the request for http://my.domain.com/project
to http://github.com/project
.
也可以在您的 Web 服务器中配置反向代理以将请求传递http://my.domain.com/project
给http://github.com/project
。
回答by VonC
If I for instance own http://myosproject.example.org, is it possible to allow git clone http://myosproject.example.organd have it actually redirect somehow to a github project instead
例如,如果我拥有http://myosproject.example.org,是否可以允许 git clone http://myosproject.example.org并让它实际上以某种方式重定向到 github 项目
It could be possible in theory if the server knew somehow to redirect the url.
Git now (2.12, Q1 2017) treat http-alternates like redirects.
如果服务器知道以某种方式重定向 url,理论上是可能的。
Git 现在(2017 年第 1 季度 2.12)将 http-alternates 视为重定向。
See commit cb4d2d3, commit 50d3413, commit fcaa6e6, commit 6628eb4, commit 986d7f4(06 Dec 2016) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit 8a2882f, 19 Dec 2016)
请参阅Jeff King ( ) 的commit cb4d2d3、commit 50d3413、commit fcaa6e6、commit 6628eb4、commit 986d7f4(2016 年 12 月 6 日)。(由Junio C Hamano合并-- --在提交 8a2882f 中,2016 年 12 月 19 日)peff
gitster
There is another way for a server to ask a git client to fetch arbitrary content: by having an http-alternates file (or a regular alternates file, which is used as a backup).
服务器还有另一种方式要求 git 客户端获取任意内容:通过使用 http-alternates 文件(或用作备份的常规替代文件)。
- unless
http.followRedirects
is set to "always", we will not follow remote redirects from http-alternates (or alternates) at all- set
CURLOPT_PROTOCOLS
alongsideCURLOPT_REDIR_PROTOCOLS
restrict ourselves to a known-safe set and respect any user-provided whitelist.- mention alternate object stores on stderr so that the user is aware another source of objects may be involved.
- 除非
http.followRedirects
设置为“always”,否则我们根本不会跟踪来自http-alternates(或alternates)的远程重定向- set
CURLOPT_PROTOCOLS
togetherCURLOPT_REDIR_PROTOCOLS
将我们自己限制在一个已知安全的集合中,并尊重任何用户提供的白名单。- 提及 stderr 上的备用对象存储,以便用户知道可能涉及另一个对象源。
Git 2.13 improves those http redirects by updating the base URL only if there is no error
Git 2.13 通过仅在没有错误时更新基本 URL 来改进这些 http 重定向
See commit 8e27391(28 Feb 2017) by Jonathan Tan (jhowtan
).
(Merged by Junio C Hamano -- gitster
--in commit d0f549f, 10 Mar 2017)
请参阅Jonathan Tan ( ) 的提交 8e27391(2017 年 2 月 28 日)。(由Junio C Hamano合并-- --在d0f549f 提交中,2017 年 3 月 10 日)jhowtan
gitster
http.c
supports HTTP redirects of the form
http.c
支持表单的 HTTP 重定向
http://foo/info/refs?service=git-upload-pack-> http://anything-> http://bar/info/refs?service=git-upload-pack
http://foo/info/refs?service=git-upload-pack-> http://anything-> http://bar/info/refs?service=git-upload-pack
That is to say, as long as the Git part of the path and the query string is preserved in the final redirect destination, the intermediate steps can have any URL.
However, if one of the intermediate steps results in an HTTP exception, a confusing "unable to update url base from redirection
" message is printed instead of a Curl error message with the HTTP exception code.Teach
http
to check the HTTP status before attempting to check if only the "base" part of the URL differed.
也就是说,只要在最终的重定向目的地中保留了路径的Git部分和查询字符串,中间步骤可以有任何URL。
但是,如果中间步骤之一导致 HTTP 异常,unable to update url base from redirection
则会打印令人困惑的“ ”消息,而不是带有 HTTP 异常代码的 Curl 错误消息。
http
在尝试检查是否只有 URL 的“基本”部分不同之前,先教检查 HTTP 状态。