我正在尝试列出其中包含“功能”的所有分支。 在此处发布之前,我引用了提供的解决方案 here
那里提供的解决方案对我不起作用 - 即; git branch --list "*feature*"
或 git branch --list\*feature\*
当我从终端尝试时,它没有按预期返回分支列表。有人可以让我知道可能是什么原因和可能的解决方案(如果有的话)。
最终目标是删除作为列表一部分返回的所有分支
最佳答案
我在本地有以下分支机构:
git branch --list
1test
2test
3test
* master
t1
t2
t3
test1
test2
test3
test4
此命令将搜索名称为test*
的本地 分支并删除它们:
git branch --list 'test*' --format '%(refname:short)' | xargs git branch -d
Deleted branch test1 (was fca79ef34c04).
Deleted branch test2 (was fca79ef34c04).
Deleted branch test3 (was fca79ef34c04).
Deleted branch test4 (was fca79ef34c04).
默认情况下,--list
只会显示本地分支。你可以在git documentation中看到您可以提供 -r
以仅显示远程分支,或提供 -a
以显示远程和本地分支。让我们更新之前的命令以适用于远程分支。
git branch --list 'test*' -r --format '%(refname:short)' | xargs git push -d origin
您也可以尝试使用带有完整引用的命令:
git branch --list 'test*' -r --format '%(refname)' | xargs git push -d origin
https://stackoverflow.com/questions/49238118/