我的目标是删除所有的分支开始的‘法力’。
PS> git branch
bug/5646
chin-dev
* dev
fea/account-manager
fea/animation
fea/charts
fea/chat
fea/dataTable
fea/enquete
fea/page-title
fea/questionnaire
fea/style
hotfix
master
merge
mod/dataTable
question
saif-dev
support我试过的命令
PS> git branch -d $(git branch | Select-String -Pattern 'fea/')
(是的,我知道Select是匹配字符串,但无论如何,在这种情况下忽略它)
命令的结果
error: branch ' fea/account-manager' not found.
...
error: branch ' fea/questionnaire' not found.
error: branch ' fea/style' not found.正如您所看到的,它返回匹配的线也有空格。这些都是用select-string删除空间的吗?
此外,我还尝试将结果toString转换为使用Trim()
PS > $(git branch | Select-String -Pattern 'fea/' ).ToString().Trim()
System.Object[]发布于 2022-09-19 08:26:10
git branch列出一组分支(没有外部命令) :git branch --list "fea/*"git branch现在支持--format=... option,这使得它更适合于脚本目的(例如:无需手动处理输出以移除前导*或前导空格):git branch --format="%(refname:short)" --list "fea/*"就Powershell处理而言:
要对命令生成的每一行(或每个对象)应用一些操作,您应该使用% { ... } (for-each-object { ... }的缩写)迭代输出:
... | % { $_.ToString().Trim() }https://stackoverflow.com/questions/73770384
复制相似问题