在 Git 2.16(2018 年第一季度)中,出现了一种新语法,其中“--format=...
“选项”git for-each-ref https://git-scm.com/docs/git-for-each-ref“学会展示
的名字remote
' 存储库和远程端的引用
受到影响的 'upstream
' and 'push
' via "%(push:remotename)
”
和朋友。
See commit 1b58686 https://github.com/git/git/commit/1b586867dba322c911cc9b4441e2be130ba76cd5 (07 Nov 2017), and commit cc72385 https://github.com/git/git/commit/cc72385fe350d4d7bc64f84e8817dbdfe27b04fe (05 Oct 2017) by Johannes Schindelin (dscho) https://github.com/dscho.
See commit 9700fae https://github.com/git/git/commit/9700fae5ee93dd0928cb82afb7b2fd49295e28d2 (07 Nov 2017) by J Wyman (whoisj) https://github.com/whoisj.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 093048b https://github.com/git/git/commit/093048b22913be23fe45635e8723d3aa3a185ff3, 15 Nov 2017)
for-each-ref
:让upstream/push选择性地报告远程名称
有时,例如脚本不仅想知道远程存储库上上游分支的名称,还想知道远程分支的名称。
该补丁提供了新的后缀: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 to DWIM https://en.wikipedia.org/wiki/DWIM如果没有明确的则推送远程
推送远程已配置;原因是 DWIM 是可能的
通过使用
%(if)%(push:remotename)%(then)
%(push:remotename)
%(else)
%(upstream:remotename)
%(end)
虽然不可能“取消 DWIM”信息,以防万一
调用者实际上只对显式推送遥控器感兴趣。
While :remote
会更短,也会更模糊,
它也会关上门,例如为了:remoteref
(这将
显然请参考远程存储库中的相应参考)。
for-each-ref
:让上游/推送报告远程引用名称
有时脚本想要知道不仅仅是名字
将分支推送到远程,而且还已知分支的名称
通过远程存储库.
一个例子是当一个工具想要推送到同一个分支时
它会自动从中拉出,即<remote>
和<to>
in git push <remote> <from>:<to>
将由以下人员提供%(upstream:remotename)
and %(upstream:remoteref)
, 分别。
该补丁提供了新的后缀:remoteref
为了upstream
and push
原子,可以准确地显示这一点。例子:
$ 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