我必须写自动化的powershell脚本克隆存储库从gihtub,但我需要安装git使用命令line.Could你请让我知道我如何才能下载和安装git在window上使用命令行没有做任何手动工作。
提前感谢!
发布于 2017-10-13 21:54:58
您可以使用chocolatey编写Git安装脚本。
该软件包在https://chocolatey.org/packages/git上提供了文档
首先,您必须install chocolatey, but that can be done on the command line.
choco install -y git
发布于 2019-12-06 17:51:58
也不想用巧克力做同样的事情。下面是我使用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其中<install inf file>是包含git安装的安装参数的文件的路径。作为示例,这是我正在使用的(我通过使用/SAVEINF=<install inf file>参数运行一次git安装程序exe获得的):
[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。
运行此命令需要重新启动shell,以便更新Path环境变量并使git命令生效。或者,您可以使用以下命令更新当前的powershell Path环境变量
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")然后,它将在path变量中包含git.exe的路径。
https://stackoverflow.com/questions/46731433
复制相似问题