在 Git 2.16(2018 年第一季度)中,有一种新语法,其中“git for-each-ref”的“--format=...”选项学会了显示
'remote' 存储库的名称和远程端的 ref
通过“%(push:remotename)”影响“upstream”和“push”
和朋友。
请参阅commit 1b58686(2017 年 11 月 7 日)和Johannes Schindelin (dscho)commit cc72385(2017 年 10 月 5 日)。
请参阅 J Wyman (whoisj) 的 commit 9700fae(2017 年 11 月 7 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit 093048b,2017 年 11 月 15 日)
for-each-ref:让上游/推送可选地报告远程名称
有时候,例如scripts 不仅想知道远程仓库的上游分支的名字,还想知道远程的名字。
此补丁为上游提供了新的后缀:remotename
推原子,可以准确地显示出来。示例:
$ cat .git/config
...
[remote "origin"]
url = https://where.do.we.come/from
fetch = refs/heads/*:refs/remote/origin/*
[remote "hello-world"]
url = https://hello.world/git
fetch = refs/heads/*:refs/remote/origin/*
pushURL = hello.world:git
push = refs/heads/*:refs/heads/*
[branch "master"]
remote = origin
pushRemote = hello-world
...
$ git for-each-ref \
--format='%(upstream) %(upstream:remotename) %(push:remotename)' \
refs/heads/master
refs/remotes/origin/master origin hello-world
实现选择 not 到 DWIM 如果没有明确的推送远程
推送远程已配置;原因是可以对这个进行 DWIM
通过使用
%(if)%(push:remotename)%(then)
%(push:remotename)
%(else)
%(upstream:remotename)
%(end)
虽然不可能“取消 DWIM”信息,以防万一
调用者实际上只对显式推送遥控器感兴趣。
虽然:remote 会更短,但也会更模糊,
它也会关上门,例如对于:remoteref(这将
明显是指远程仓库中对应的ref)。
for-each-ref: 让 upstream/push 报告远程 ref 名称
有时脚本想要知道不仅是
在远程推送分支,还有已知的分支名称
通过远程存储库。
一个例子是当一个工具想要推送到同一个分支时
它将自动从中拉出,即<remote> 和<to>
在git push <remote> <from>:<to> 将由提供
分别为%(upstream:remotename) 和%(upstream:remoteref)。
此补丁为upstream 和push 提供了新的后缀:remoteref
原子,可以准确地表明这一点。示例:
$ cat .git/config
...
[remote "origin"]
url = https://where.do.we.come/from
fetch = refs/heads/*:refs/remote/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "develop/with/topics"]
remote = origin
merge = refs/heads/develop/with/topics
...
$ git for-each-ref \
--format='%(push) %(push:remoteref)' \
refs/heads
refs/remotes/origin/master refs/heads/master
refs/remotes/origin/develop/with/topics refs/heads/develop/with/topics