git - 使用通配符过滤 git 分支

我正在尝试列出其中包含“功能”的所有分支。 在此处发布之前,我引用了提供的解决方案 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/

相关文章:

ms-access - 从 VBA Access 中的函数返回数据类型时收到 'Invalid Us

python - 从python字符串中删除大写字母

antd - 为选择的多个组件设置默认初始值

vuejs2 - 在 vue.js 中捕获 API 请求中的错误

scala - 扁平化 future 内部 yield

mongodb - 使用 Mongoose 和 SRV 连接字符串将数据插入 MongoDB Atl

css - Flex 布局 - "flex-basis: 1e-09px"是什么意思?

php - Laravel 存储库和多个相关模型

apache-kafka - 一对多KStream-KTable连接

reactjs - 我如何将两个 Prop 从 jsx 传递到 scss