gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 09:16:57 25 4
gpt4 key购买 nike

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

关于git - 使用通配符过滤 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49238118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com