git branch --list的仅命名选项? [英] Name only option for `git branch --list`?

查看:38
本文介绍了git branch --list的仅命名选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git branch 输出分支列表,但在当前分支旁边也输出其他以人为本的绒毛,例如星号( * ).

  $ git分支*(在原点/原点分离的HEAD)branch_foo一些/branch_bar 

如何获得更多机器可解析的输出(例如,只是分支的名称)以供脚本使用等?

解决方案

用于处理引用的通用脚本命令是 git for-each-ref .

分支引用位于名称空间的 refs/heads/部分中,因此请使用 git for-each-ref refs/heads 来全部获取./p>

默认情况下, git for-each-ref 打印三个项目:'%(objectname)%(objecttype)%(refname)',使用其他-format 进行更改.在这种情况下,您可能想要:

  git for-each-ref --format ='%{refname:short)'参考/头 

但请参见文档用于所有可用的格式设置指令.(另请注意,git 2.6和2.7中对 git for-each-ref 给予了相当多的关注:-包含-合并-no-merged -points-at 是新的.在git的旧版本中,前三个只能通过 git分支.)

git branch outputs a list of branches, but also outputs other human-oriented fluff such as an asterisk (*) beside the current branch.

$ git branch
* (HEAD detached at origin/master)
  branch_foo
  some/branch_bar

How do I get a more machine parsable output (e.g. just the name of branches) for scripting use etc.?

解决方案

The general scripting command for working with references is git for-each-ref.

Branch references live in the refs/heads/ part of the name-space, so use git for-each-ref refs/heads to obtain them all.

By default, git for-each-ref prints three items: '%(objectname) %(objecttype) %(refname)', Use a different --format to change this. In this case, you probably want:

git for-each-ref --format='%(refname:short)' refs/heads

but see the documentation for all the available formatting directives. (Note also that git for-each-ref got a fair bit of attention in git 2.6 and 2.7: --contains, --merged, --no-merged, and --points-at are new. In older versions of git, the first three are only available via git branch.)

这篇关于git branch --list的仅命名选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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