为什么一些版本库URL以.git结尾而其他版本则不以? [英] Why do some repository URLs end in .git while others don't?

查看:454
本文介绍了为什么一些版本库URL以.git结尾而其他版本则不以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我克隆版本库时,这两个URL是否有区别?


$ b


  1. 没有.git扩展名:

      git clone http:// foo / repo 


  2. 使用.git扩展名:

      git clone http:// foo / repo.git 



解决方案

惯例是, .git 扩展名应该用于裸存储库,并且不得与具有工作树的目录一起使用。 Git并没有真正关心,但有一些便利方法可以使它相当透明。

例如,如果您有一个名为 / tmp / foo的存储库.git ,然后调用 git clone file:/// tmp / foo ,Git将首先尝试查找 / tmp / foo 。如果它不存在,它会尝试使用 /tmp/foo.git



这样做不是 反过来工作。如果您的目录名为 / tmp / foo ,并且您尝试从 /tmp/foo.git 进行克隆,您将被告知:


致命:'/tmp/foo.git'似乎不是git存储库




大多数HTTP / HTTPS功能来自您的Web服务器,而不是Git。即使您使用智能HTTP传输,我怀疑大部分的魔法都发生在一个服务器端的LocationMatch指令。除此之外,对GitHub的一些快速测试表明它在这方面的工作方式与SSH和Git procotols相同,但是其他Web服务器上的里程可能会有所不同。


When I clone a repository, is there any difference between these two URLs?

  1. Without .git extension:

    git clone http://foo/repo
    

  2. With .git extension:

    git clone http://foo/repo.git
    

解决方案

The convention is that the .git extension should be used for bare repositories, and left off of directories with a working tree. Git doesn't really care, but has a few convenience methods that make this fairly transparent.

For example, if you have a repository named /tmp/foo.git and you call git clone file:///tmp/foo, Git will first try to find /tmp/foo. If it doesn't exist, it will try /tmp/foo.git instead.

This does not work the other way around. If your directory is named /tmp/foo and you try to clone from /tmp/foo.git you will be told:

fatal: '/tmp/foo.git' does not appear to be a git repository

Most of the HTTP/HTTPS functionality is from your web server, not Git. Even if you're using Smart HTTP transport, I suspect most of the magic happens in a server-side LocationMatch directive. Theory aside, some quick tests against GitHub show that it works the same way as the SSH and Git procotols in that respect, but your mileage may vary on other web servers.

这篇关于为什么一些版本库URL以.git结尾而其他版本则不以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆