[英]By given name of a Git remote-tracking branch how to find which local branch tracks it?
通過 Git 遠程跟蹤分支的給定名稱,例如, upstream/develop
如何找到哪個本地分支跟蹤它(如果有)?
如果可能的話,我正在尋找一種不依賴於 shell 腳本並且也適用於 Windows 的解決方案。
另一種方法是使用帶有for-each-ref
的條件格式
git for-each-ref --format="%(if:equals=upstream/develop)%(upstream:short)%(then)%(refname:short)%(end)" refs/heads | sort -u
可以更方便地放入別名中
git config --global alias.who-tracks '!f() { git for-each-ref --format="%(if:equals=upstream/$1)%(upstream:short)%(then)%(refname:short)%(end)" refs/heads | sort -u; }; f'
# then when you need it :
git who-tracks develop
git who-tracks another/branch
在這個別名中,我假設了一個唯一的遙控器,但當然,如果您希望能夠在不同的遙控器上使用它,請稍作調整以在參數中包含遙控器名稱:
git config --global alias.who-tracks '!f() { git for-each-ref --format="%(if:equals=$1)%(upstream:short)%(then)%(refname:short)%(end)" refs/heads | sort -u; }; f'
# then when you need it :
git who-tracks upstream/develop
git who-tracks origin/another/branch
另一種選擇是使用 grep 過濾簡單git branch
的非常冗長的grep
git branch -vv | grep upstream/develop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.