例如,假設我在 GitLab 上查看了這個小專案:
git clone https://gitlab.com/gitlab-examples/functions.git
cd functions
git rev-parse --short HEAD
# c1fccc0
git branch -l
# * master
因此,默認情況下,克隆后我們在master分支中,在 commit c1fccc0。
現在,我想在這個提交中獲取顯示 git 專案目錄(即樹視圖)的遠程 URL。事實證明,GitLab 上的 URL 是https://gitlab.com/gitlab-examples/functions/-/tree/c1fccc0/ - 所以,我原則上可以bash像這樣生成這個 URL:
echo $(echo $(git config remote.origin.url) | sed 's/\.git//')/-/tree/$(git rev-parse --short HEAD)/
# https://gitlab.com/gitlab-examples/functions/-/tree/c1fccc0/
到目前為止一切都很好——但是,如果我查看一個 GitHub 專案,邏輯會略有不同;這是另一個示例小專案:
git clone https://github.com/codepr/llb.git
git branch -l && git rev-parse --short HEAD
# * master
# b4a6a66
然而,在這里,檔案的樹視圖位于https://github.com/codepr/llb/tree/b4a6a66/(帶或不帶最后一個斜杠) - 因此獲取此 URL 的代碼現在不同:
echo $(echo $(git config remote.origin.url) | sed 's/\.git//')/tree/$(git rev-parse --short HEAD)/
# https://github.com/codepr/llb/tree/b4a6a66/
那么,是否有一個git內部命令,它會以一種或另一種方式“知道”遠程 URL 的構建方式,并可以在遠程樹視圖中為當前提交生成一個 URL/Web 鏈接——前提是遠程是 HTTP (S)?
uj5u.com熱心網友回復:
那么,是否有一個 git 內部命令,它以一種或另一種方式“知道”遠程 URL 的構造方式......
一點都不。git了解 Git 物件資料庫和 Git 協議。資料庫的 Web 界面是 Git 托管的屬性,它們故意做不同的事情以抓住供應商鎖定的用戶。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/520041.html
