1

有很多在 Linux 和 Unix 中执行后将Subversion分支转换为 Git标签的示例。git svn clone我能够使用从这篇博客文章到这一步的步骤(文章中的第 6 步)。我需要将脚本移植到 PowerShell。这是Linux版本:

git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done

以下是我目前所拥有的 PowerShell 版本:

git for-each-ref --format='%(refname)' refs/heads/tags |
# not sure how to replace "cut"
do {
    git tag "$ref" "refs/heads/tags/$ref";
    git branch -D "tags/$ref";
} while (<# I'm assuming I'm iterating a collection but I'm not sure what or how. should this be a foreach instead? #>)
done
4

1 回答 1

1

我对 UNIX 和 git 没有太多经验,所以这几乎是猜测。尝试:

& git for-each-ref --format='%(refname)' refs/heads/tags | % {
    #Extract the 4th field from every line
    $_.Split("/")[3]
} | % {
    #Foreach value extracted in the previous loop
    & git tag $_ "refs/heads/tags/$_"
    & git branch -D "tags/$_"
}
于 2013-02-08T20:17:46.363 回答