【发布时间】:2015-10-31 02:38:39
【问题描述】:
我正在寻找在 PowerShell 脚本中为每个 Git 远程分支执行函数的最佳方法。
我不知道获取 Git 远程分支列表的最佳方法。我可以成功列出所有远程分支,但我总是在分支名称中出现讨厌的格式。
这是我尝试过的命令以及我得到的结果数组。
$allBranches = git branch -r
$allBranches = @(' origin/branch1', ' origin/branch2', ' origin/branch3')
$allBranches = git for-each-ref --shell --format=%(refname) refs/remotes/origin
$allBranches = @(''origin/branch1'', ''origin/branch2'', ''origin/branch3'')
我想要
$allBranches = @('origin/branch1', 'origin/branch2', 'origin/branch3'),所以我目前的方法是使用 Trim() 从奇怪的分支名称中手动删除格式:
foreach($branch in $allBranches) {
# Format $branch
# Do function
}
有更好的方法吗?
【问题讨论】:
-
stackoverflow.com/questions/3846380/… 标题中有 Bash,但确实包含您想要的 Git 魔法
-
您是在寻找 Powershell 代码来轻松格式化返回的分支名称,还是寻找不包含额外空格的更好的 git 调用?
-
我正在寻找 Powershell 脚本,而不是 Bash 脚本。我知道如何格式化分支名称。我想要一个更好的 git 调用或更好的方法来遍历分支。
标签: git powershell foreach git-branch