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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:13:21  来源:igfitidea点击:

Git & redirections

git

提问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 -vis 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.organd 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 .gitfolder) is in the web servers DocumentRoot, and you set up a specific post-updatehook, 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 Arecord (if you know the IP address) or a CNAMErecord (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/projectto http://github.com/project.

也可以在您的 Web 服务器中配置反向代理以将请求传递http://my.domain.com/projecthttp://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 cb4d2d3commit 50d3413commit fcaa6e6commit 6628eb4commit 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.followRedirectsis set to "always", we will not follow remote redirects from http-alternates (or alternates) at all
  • set CURLOPT_PROTOCOLSalongside CURLOPT_REDIR_PROTOCOLSrestrict 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_PROTOCOLStogetherCURLOPT_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.csupports 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 httpto 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 状态。