2013-02-08 57 views
1

後有大量的轉換顛覆分支到Git 標籤在Linux和Unix進行git svn clone後的例子。我能夠使用此博客post中的步驟直至此步驟(post中的步驟6)。我需要將腳本移植到PowerShell。這裏的Linux版本:轉換所有的Subversion分支Git標籤使用PowerShell混帳SVN

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 
+1

在Windows 10和Windows最新的git(我使用的是64位),Git的猛砸視窗的偉大工程(我用它來代替的PowerShell爲許多這些事情)。 – Fuhrmanator 2017-09-21 14:27:48

回答

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/$_" 
}