希望在不使用巧克力的情况下做同样的事情。以下内容对我有用,使用 powershell 下载并安装 64 位版本的 git-for-windows:
# get latest download url for git-for-windows 64-bit exe
$git_url = "https://api.github.com/repos/git-for-windows/git/releases/latest"
$asset = Invoke-RestMethod -Method Get -Uri $git_url | % assets | where name -like "*64-bit.exe"
# download installer
$installer = "$env:temp\$($asset.name)"
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $installer
# run installer
$git_install_inf = "<install inf file>"
$install_args = "/SP- /VERYSILENT /SUPPRESSMSGBOXES /NOCANCEL /NORESTART /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /LOADINF=""$git_install_inf"""
Start-Process -FilePath $installer -ArgumentList $install_args -Wait
Where <install inf file>
是包含 git 安装的安装参数的文件的路径。作为一个例子,这是我正在使用的(我通过使用 git installer exe 运行一次来获得它)/SAVEINF=<install inf file>
范围):
[Setup]
Lang=default
Dir=C:\Program Files\Git
Group=Git
NoIcons=0
SetupType=default
Components=ext,ext\shellhere,ext\guihere,gitlfs,assoc,autoupdate
Tasks=
EditorOption=VIM
CustomEditorPath=
PathOption=Cmd
SSHOption=OpenSSH
TortoiseOption=false
CURLOption=WinSSL
CRLFOption=LFOnly
BashTerminalOption=ConHost
PerformanceTweaksFSCache=Enabled
UseCredentialManager=Enabled
EnableSymlinks=Disabled
EnableBuiltinInteractiveAdd=Disabled
从类似问题的答案中了解了安装参数文件:https://superuser.com/a/1005634/1104046 https://superuser.com/a/1005634/1104046.
运行此命令将需要重新启动 shell,以便更新 Path 环境变量并使 git 命令正常工作。或者,您可以使用以下命令更新当前的 powershell Path 环境变量
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
然后,它将在 Path 变量中包含 git.exe 的路径。