git相關的一個問答:
使用git clone時,如果后面跟的是http協議的url,那么服務器端會作何處理,才會返回版本庫? 例如url:https://github.com/pallets/flask 既可以使用瀏覽器訪問,也可以使用git客戶端工具進行克隆,不過克隆出來的是一個目錄,據我所知,目前網頁不能直接返回一個目錄,只能返回一個文件。 那么問題來了: 1,git客戶端訪問該url時,網站是否返回了一個包含該目錄的所有文件列表,從而使git客戶端去遍歷下載這些文件。 2,如果1成立,那么服務器端應該如何判定訪問的是git客戶端,而不是瀏覽器。 3,如果1成立,那么服務器端返回的文件列表是什么格式的? 4,從哪里可以了解到這些技術規范? 一般是三種情況。 情況一:實現了 Smart HTTP Protocol 的 git 客戶端此時 git 客戶端會嘗試判斷服務端是否支持 Smart HTTP Protocol, 如果支持就用 git 自己的協議傳輸, 否則就從服務器上一個個文件分別下載下來(即退回到情況二所述的 Dumb HTTP Protocol)。 情況二:未實現 Smart HTTP Protocol 的 git 客戶端這種貌似現在比較少見, 此時 git 客戶端會自己一個一個把文件下載下來。 拉取時(貌似)只會拉取 repo 地址下 info/refs 獲取遠端 object 列表,然后通過類似 objects/d0/49f6c27a2244e12041955e262a404c7faba355 的路徑下載單獨的 object, 不會直接訪問到 repo 地址。 情況三:客戶端是網頁瀏覽器這種情況下一般會有比較明顯的 User-Agent 標記這是個瀏覽器, 而且瀏覽器會訪問的地址一般也會避開 Dumb HTTP Protocol 會用到的地址。 不過也有些情況下服務器端會簡化設計, 直接要求瀏覽器和 git 使用不同的 repo url(之前用過 SCM Manager 搭服務端,貌似就是這么設計的,不過沒實際證實)。 詳細的內容可以參閱 git 源碼里的 Documentation/technical/http-protocol.txt, 以及同一個目錄的 pack-protocol.txt 和 protocol-capabilities.txt。
1,git獲取repo
下載repo git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo 將git-repo中的repo文件復制到 1 創建的.bin目錄中 cd git-repo cp repo ~/.bin/
2,wget並不能替換git clone:比如獲取 repo:
如果采用wget https://xxxxxx 獲取repo 失敗!得到是網頁 wget https://gerrit-googlesource.lug.ustc.edu.cn/git-repo --2021-04-05 13:53:35-- https://gerrit-googlesource.lug.ustc.edu.cn/git-repo Resolving gerrit-googlesource.lug.ustc.edu.cn (gerrit-googlesource.lug.ustc.edu.cn)... 192.109.232.118, 2400:ddc0:1000::6417:bae0 Connecting to gerrit-googlesource.lug.ustc.edu.cn (gerrit-googlesource.lug.ustc.edu.cn)|192.109.232.118|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://gerrit-googlesource.proxy.ustclug.org/git-repo [following] --2021-04-05 13:53:36-- https://gerrit-googlesource.proxy.ustclug.org/git-repo Resolving gerrit-googlesource.proxy.ustclug.org (gerrit-googlesource.proxy.ustclug.org)... 192.109.232.118, 2400:ddc0:1000::6417:bae0 Connecting to gerrit-googlesource.proxy.ustclug.org (gerrit-googlesource.proxy.ustclug.org)|192.109.232.118|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘git-repo.1’ [ <=> ] 10,228 --.-K/s in 0s 2021-04-05 13:53:36 (157 MB/s) - ‘git-repo.1’ saved [10228] wget https://gerrit-googlesource.lug.ustc.edu.cn/git-repo/repo --2021-04-05 13:22:07-- https://gerrit-googlesource.lug.ustc.edu.cn/git-repo/repo Resolving gerrit-googlesource.lug.ustc.edu.cn (gerrit-googlesource.lug.ustc.edu.cn)... 192.109.232.118, 2400:ddc0:1000::6417:bae0 Connecting to gerrit-googlesource.lug.ustc.edu.cn (gerrit-googlesource.lug.ustc.edu.cn)|192.109.232.118|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://gerrit-googlesource.proxy.ustclug.org/git-repo/repo [following] --2021-04-05 13:22:07-- https://gerrit-googlesource.proxy.ustclug.org/git-repo/repo Resolving gerrit-googlesource.proxy.ustclug.org (gerrit-googlesource.proxy.ustclug.org)... 192.109.232.118, 2400:ddc0:1000::6417:bae0 Connecting to gerrit-googlesource.proxy.ustclug.org (gerrit-googlesource.proxy.ustclug.org)|192.109.232.118|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2021-04-05 13:22:08 ERROR 404: Not Found.
如果鏈接不是指向一個資源文件,那么會得到一個網頁
即:只是簡單下載。
3,curl例子:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
4,補充:
(apt-get、wget、git clone、pip與pip3區別、apt-get和pip區別)
