我编写了一个powershell脚本来获取git子模块并设置他的分支。它将从管道运行,分支名称将从启动表单输入传递。
Param(
[Parameter(Mandatory=$false)]
[string]$branch = ""
)
cd "$PSScriptRoot\.."
git submodule update --init --recursive
Write-Host "Got branch $branch"
if (-not [string]::IsNullOrWhiteSpace($branch)) {
cd "submodule"
git checkout "origin/$branch"
Write-Host "Installed branch $branch"
} else {
Write-Host "Installed default branch"
}
问题在于
git checkout "origin/$branch"
它满足了我的需要,但显示了警告。有没有更正确的方法来实现它的目的?
关于
detached HEAD
状态的警告?警告本身会告诉您如何避免它出现。
Turn off this advice by setting config variable advice.detachedHead to false
所以,像这样的东西就足够了:
git -c advice.detachedHead=false checkout "origin/$branch"