简体   繁体   中英

Convert All Subversion Branches to Git Tags Using PowerShell After a git svn

There are lots of examples of converting Subversion branches to Git tags after performing git svn clone in Linux and Unix. I was able to use the steps from this blog post up to this step (step 6 in the post ). I need to port the script to PowerShell. Here's the Linux version:

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

Here's what I have so far for the PowerShell version:

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

I don't have much experience with UNIX and git, so this is pretty much guessing. Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM