循环所有具有特定名称的git分支 [英] for loop over all git branches with certain name
问题描述
我有以下git分支机构
foo
bar
foobar
特性/ foo
功能/栏
功能/ buzz
循环以'feature /'开头的所有分支?
当我尝试以下操作时,奇怪地打印出的不仅仅是git分支。
for i in $(git branch --listfeature / *);做echo $ i;完成;
stuff.txt
icon.jpg
morestuff.txt
Vagrantfile
功能/ foo
功能/栏
功能/ buzz
我们积极劝阻不要使用任何Porcelain命令,包括git分支,在脚本中 - 来自 Git Maintainer的博客
您想使用类似于
git for-each-ref - -format ='%(refname:short)'refs / heads / feature /
可以在 for $ in $()
构造
I have the following git branches
foo
bar
foobar
feature/foo
feature/bar
feature/buzz
How would you do a for loop over all branches that start with the word 'feature/' ?
When I try the following, it strangely prints out more than just the git branches.
for i in $(git branch --list "feature/*"); do echo $i; done;
stuff.txt
icon.jpg
morestuff.txt
Vagrantfile
feature/foo
feature/bar
feature/buzz
"We actively discourage against use of any Porcelain command, including git branch, in scripts" - from the Git Maintainer's Blog
You want to use something like
git for-each-ref --format='%(refname:short)' refs/heads/feature/
which will work fine inside a for br in $()
construct
这篇关于循环所有具有特定名称的git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!