特定遥控器的分支名称的Git列表 [英] Git list of branch names of specific remote

查看:73
本文介绍了特定遥控器的分支名称的Git列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取某个远程起源分支的所有名称?

How can it possible to get all names of some remote origin branches?

我从--remote --list选项开始,但是得到了冗余的origin/HEAD -> origin/master消息并从另一个来源分支.

I started from --remote --list options, but got redundant origin/HEAD -> origin/master message and branches from the another origin.

$> git branch --remote --list
  origin/HEAD -> origin/master
  origin1/develop
  origin1/feature/1
  origin1/feature/2
  origin1/feature/3
  origin1/master
  origin2/develop
  origin2/feature/1
  origin2/feature/2
  origin2/master

特定来源的分支可以与<pattern>选项匹配,但是仍然存在冗余消息.实际上,这种模式并不是真正正确的,因为某个起源的名称可能是另一个起源名称的子字符串,甚至可能是某个分支.

Branches of specific origin could be matched with <pattern> option, but redundant message is still there. Actually that pattern is not really correct, because some origin's name could be a substring of another origin name, or even some branch.

$> git branch --remote --list origin1*
  origin1/HEAD -> origin/master
  origin1/develop
  origin1/feature/1
  origin1/feature/2
  origin1/feature/3
  origin1/master

我要查找的是origin1分支名称的列表,这些分支名称都可以用于git checkout命令.像这样的东西:

What am I looking for is a list of branch names of origin1, any of them I could use for git checkout command. Something like that:

develop
feature/1
feature/2
feature/3
master

重要的是,由于它们的不安全性和变化性,应该在没有grepsedtail或什至ghc -e包装的情况下,仅使用真正的git功能进行包装.

It's important that it should be done without grep, sed, tail or even ghc -e wrappers, only with true git power, because of their unsafeness and variation.

推荐答案

重要的是,由于它们的不安全性和差异性,应该在没有grepsedtail甚至ghc -e包装器的情况下,仅使用真正的git power进行操作.

It's important that it should be done without grep, sed, tail or even ghc -e wrappers, only with true git power, because of their unsafeness and variation.

这仅适用于git瓷器命令(请参阅"

That is only true for git porcelain commands (see "What does the term porcelain mean in Git?")

使用管道命令 ls-remote ,然后您将能够过滤其输出.

Use the plumbing command ls-remote, and then you will be able to filter its output.

不带参数的ls-remote仍会列出远程HEAD:

ls-remote without parameter would still list the remote HEAD:

git@vonc-VirtualBox:~/ce/ce6/.git$ git ls-remote origin
8598d26b4a4bbe416f46087815734d49ba428523    HEAD
8598d26b4a4bbe416f46087815734d49ba428523    refs/heads/master
38325f657380ddef07fa32063c44d7d6c601c012    refs/heads/test_trap

但是,如果您只要求说遥控器的头:

But if you ask only for the heads of said remote:

git@vonc-VirtualBox:~/ce/ce6/.git$ git ls-remote --heads origin
8598d26b4a4bbe416f46087815734d49ba428523    refs/heads/master
38325f657380ddef07fa32063c44d7d6c601c012    refs/heads/test_trap

最终答案:

git@vonc-VirtualBox:~/ce/ce6/.git$ git ls-remote --heads origin  | sed 's?.*refs/heads/??'
master
test_trap

(是的,它使用sed,但是管道命令的输出应该足够稳定以至于可以解析)

(Yes, it uses sed, but the output of a plumbing command is supposed to be stable enough to be parsed)

另请参见 Git 2.23(2019年第三季度),其中提供了示例:

git branch -r -l '<remote>/<pattern>'
git for-each-ref 'refs/remotes/<remote>/<pattern>'

这篇关于特定遥控器的分支名称的Git列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆