Git“获取 URL”和“推送 URL”有什么区别?

发布于 2024-10-08 09:43:37 字数 668 浏览 4 评论 0原文

对于某个远程,什么时候 Fetch URL 和 Push URL 会不相同?

例如,当我为名为central的远程运行git remote showcentral时,输出如下所示:

* remote central
  Fetch URL: [email protected]:/home/aoberoi/Repositories/example.git
  Push  URL: [email protected]:/home/aoberoi/Repositories/example.git
  HEAD branch: master
  Remote branch:
    master tracked

我只是不明白为什么我会从两个不同的URL中获取和推送到两个不同的URL,什么类型的工作流程的用途是什么?

When would the Fetch URL and Push URL not be the same for a certain remote?

For example, when i run git remote show central for a remote named central, the output looks like:

* remote central
  Fetch URL: [email protected]:/home/aoberoi/Repositories/example.git
  Push  URL: [email protected]:/home/aoberoi/Repositories/example.git
  HEAD branch: master
  Remote branch:
    master tracked

I just don't see why I would be fetching from and pushing to two different URLs, what type of workflow is this intended for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行雁书 2024-10-15 09:43:37

我不确定您的意思,因为您的示例包含 2 个相同 URL,但推送和拉取的 URL 可能不同,因为:

  • 协议问题:请参阅 Git 协议:网址将略有不同,因为并非每个协议都支持推送操作(例如 http,除了 smart http< /a>)
  • 中间存储库:您可以推送到不同的存储库,该存储库将成为真正的“中央”存储库和您的存储库之间的“中间人”。然后可以执行某些操作(例如通过接收后挂钩),如果这些操作(例如“单元测试”、“静态代码分析”...... ) 成功通过。
    有关此类用法的示例,请参阅:
    < strong>您见过的源存储库最巧妙的用法是什么?”。

话虽这么说,提交 697f652(Git 2.3.1+,2015 年第一季度/第二季度) Git 维护者 Junio C Hamano (gitster) 提到:

尝试使用单个远程(例如“来源”)从一个地方(即上游)获取数据,同时推送到另一个地方(即您的发布点)似乎是一个常见的错误。< /p>

这永远不会令人满意,如果你想想 refs/remotes/origin/* 在这样的世界中意味着什么,就很容易理解为什么。它根本不能反映现实。
如果它遵循你的上游状态,它就无法与你所拥有的相匹配
发布,反之亦然。

文档并不清楚“remote..pushURL”和“remote..URL”是用来命名的通过不同的传输访问同一存储库,不是两个单独的存储库

I am not sure what you mean, since your example includes 2 identical URL, but URLS for push and pull can differ because of:

  • protocol issue: see Git protocols: the url will be slightly different because not every protocol supports push operations (http for instance, except in case of smart http)
  • intermediate repos: you can push to a different repository which will be the "middle man" between the true "central" repo and yours. Certains operations can then be performed (through a post-receive hook for instance), and the commit will then be pushed to the "actual" remote from there if those operations (like "unit testing", "static code analysis" ...) pass successfully.
    For instance of such a usage, see:
    "What is the cleverest use of source repository that you have ever seen?".

That being said, commit 697f652 (Git 2.3.1+, Q1/Q2 2015) by Git maintainer Junio C Hamano (gitster) do mention:

It seems to be a common mistake to try using a single remote (e.g. 'origin') to fetch from one place (i.e. upstream) while pushing to another (i.e. your publishing point).

That will never work satisfactorily, and it is easy to understand why if you think about what refs/remotes/origin/* would mean in such a world. It fundamentally cannot reflect the reality.
If it follows the state of your upstream, it cannot match what you have
published, and vice versa.

The documentation wasn't clear that "remote.<nick>.pushURL" and "remote.<nick>.URL" are there to name the same repository accessed via different transports, not two separate repositories.

深空失忆 2024-10-15 09:43:37

我认为,如果您想要一个“暂存”存储库贡献者会推送到的存储库,然后其他人会在审核和批准后将更改从那里推送到主存储库,那么您可以使用它。因此,您可以从主存储库中获取数据,然后推送到临时存储库。

I think you could use it if you wanted a "staging" repo contributors would push to, and then others would push changes from there to the main repo after review and approval. So you'd fetch from the main repo, and push to the staging repo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文