使用Powershell和Git编译

时间:2018-01-09 22:50:17

标签: git powershell

我一直在研究一个遍历所有git目录的PowerShell脚本,其目标是如果对遥控器进行任何更改,执行拉动然后编译源代码。

我有一个工作脚本,但当我手动拉动时,我发现我没有提取信息。

我从中获取的一个存储库是boost存储库(https://github.com/boostorg/boost.git)。该项目有一个主要项目和子项目数量。

我在Windows上通过PowerShell运行它。我也安装了posh-git。

脚本执行的第一件事就是将cd放入git目录(... Boost \ boost-git)。之后我执行以下操作:

Write-Host "git status"
git status

Write-Host "git branch"
git branch

$RemoteBranch = git remote
Write-Host "Remote       : '$RemoteBranch'"

if ($RemoteBranch -ne $null) {
    $RemoteURL = git remote get-url --all $RemoteBranch
    Write-Host "Remote URL   : '$RemoteURL'"
}

Write-Host "`ngit branch | ForEach-Object { Get-GitStatus $_. }"
git branch | ForEach-Object {
    $status = Get-GitStatus $_.
    $status
    $BehindBy += $status.BehindBy
}

Write-Host "`ngit diff-index --quiet HEAD"
$GitHead = git diff-index --quiet HEAD
$GitHead
if ($GitHead -ne "") {
    Write-Host "`nNo Changes"
} else {
    Write-Host "`nChanges"
    $GitHead
}

Write-Host "`nBehindBy Sum $BehindBy"

if ($BehindBy -gt 0) {
    git fetch --all
}

当脚本运行时,我不会在更新遥控器时拉动存储库。

非常感谢任何帮助,或者让我知道我应该解析哪些命令。

1 个答案:

答案 0 :(得分:1)

经过更多搜索,我找到了答案如何做到这一点。它可以在 Check if pull needed in Git

很好地介绍了可以适应powershell的不同bash策略,作者解释了每个命令。