【问题标题】:for loop over all git branches with certain namefor 循环遍历具有特定名称的所有 git 分支
【发布时间】:2014-12-30 17:36:20
【问题描述】:

我有以下 git 分支

foo
bar
foobar
feature/foo
feature/bar
feature/buzz

您将如何对所有以单词 'feature/' 开头的分支进行 for 循环?

当我尝试以下操作时,它奇怪地打印出的不仅仅是 git 分支。

for i in $(git branch --list "feature/*"); do echo $i; done;
stuff.txt
icon.jpg
morestuff.txt
Vagrantfile
feature/foo
feature/bar
feature/buzz

【问题讨论】:

标签: git


【解决方案1】:

“我们强烈反对在脚本中使用任何 Porcelain 命令,包括 git 分支”——来自Git Maintainer's Blog

你想使用类似的东西

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

for br in $() 构造中可以正常工作

【讨论】:

    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多