代码之家  ›  专栏  ›  技术社区  ›  InteXX

如何将本地更改同步到第二个Git存储库?

  •  0
  • InteXX  · 技术社区  · 6 年前

    origin 在他的VSTS账户中有回购。

    this approach

    cd /path/to/local/repo
    git remote add tfs url://tfs/git/repo
    git push --mirror tfs
    

    remote add

    D:\Agent\_work\37\s>git remote add Application https://customer.visualstudio.com/Applications/_git/Application
    Rename from 'D:/Agent/_work/37/s/.git/config.lock' to 'D:/Agent/_work/37/s/.git/config' failed. Should I try again? (y/n)
    

    push 到TFS。因此,我似乎无法告诉TFS有关远程VSTS存储库的信息。

    1 回复  |  直到 6 年前
        1
  •  0
  •   InteXX    6 年前

    1. https://stackoverflow.com/a/45224858/722393
    2. https://stackoverflow.com/a/50925741/722393

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)][string] $Application,
        [Parameter(Mandatory)][string] $LocalPath,
        [Parameter(Mandatory)][string] $Token
    )
    
    . \\SERVER\Scripts\TfsBuild\Invoke-Git.ps1 
    
    $RemoteExists = $false
    $AllRemotes = git remote
    
    ForEach($Remote in $AllRemotes) {
        If($Remote = $Application) {
            $RemoteExists = $true
            Break
        }
    }
    
    If($RemoteExists) {
        Invoke-Git -Command "remote remove $Application"
    }
    
    Invoke-Git -Command "remote add $Application https://Personal%20Access%20Token:$Token@customer.visualstudio.com/Applications/_git/$Application"
    Set-Location $LocalPath
    Invoke-Git -Command "push --mirror HydraMonitor"
    

    <#
    .Synopsis
        Invoke git, handling its quirky stderr that isn't error
    
    .Outputs
        Git messages, and lastly the exit code
    
    .Example
        Invoke-Git push
    
    .Example
        Invoke-Git "add ."
    #>
    Function Invoke-Git
    {
    param(
    [Parameter(Mandatory)]
    [string] $Command )
    
        Write-Output "##[command]. git $Command"
    
        Try {
            $Exit = 0
            $Path = [System.IO.Path]::GetTempFileName()
    
            Invoke-Expression "git $Command 2> $Path"
    
            $Exit = $LASTEXITCODE
    
            If ( $Exit -gt 0 ) {
                Write-Error (Get-Content $Path).ToString()
            }
            Else {
                Get-Content $Path
            }
    
            "Exit code: $Exit"
        }
        Catch {
            Write-Host "Error: $_`n$($_.ScriptStackTrace)"
        }
        Finally {
            If ( Test-Path $Path ) {
                Remove-Item $Path
            }
        }
    }