缺少 git 支持,请使用“Install-Module posh-git”安装 posh-git 并重新启动 cmder。

11
我想使用cmder powershell工具来使用git。

错误信息

Cmder提示以下错误信息:

缺少git支持,请通过'Install-Module posh-git'安装posh-git并重新启动cmder。

如果我运行Install-Module posh-git,cmder会打印出下一个错误:

  • Install-Module <<<< posh-git
    • CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

我已尝试的方法

问题

我的git命令可以使用,但是没有显示我正在使用的分支。

那么我应该如何解决这个问题?


手动安装了 posh-git。 <-- 你在这里做了什么? - Ryan Bemrose
你正在使用哪个版本的PowerShell?Install-Module需要3.0或更高版本。 - Ryan Bemrose
我按照这里的posh git安装(手动)指南:链接进行操作。 我的PowerShell版本是2.0 -> 所以我将尝试更新PowerShell并再次运行该命令“Install-Module posh-git”。 - Fabian Schmick
你的CommandNotFoundException是因为Install-Module需要Powershell 3.0或安装了PSGet。但是,手动安装应该可以解决问题。请验证文件posh-git.psm1是否位于$env:PSModulePath中的某个位置。 - Ryan Bemrose
另外,如果你还没有这样做的话,在运行 install.ps1 后尝试重新启动 PowerShell。然后运行 Import-Module posh-git - Ryan Bemrose
显示剩余2条评论
2个回答

22

如果不需要posh-git,请按照以下步骤进行操作。posh-git可能会导致提示的显示出现显著延迟。

在cmder配置文件(vendor\profile.ps1)中,将"checkGit"函数中的以下行注释掉即可。

function checkGit($Path) {
    #if (Test-Path -Path (Join-Path $Path '.git')) {
    #    $gitLoaded = Import-Git $gitLoaded
    #    Write-VcsStatus
    #    return
    #}

注意:很抱歉,这个回答没有回答原始请求以查看当前分支。我认为这个解决方案可能更适合一些人。

更新:

以下是一个更好的解决方案,不需要每次更新 cmder 时重新应用:

将以下函数添加到 \config\user_profile.ps1(我的 chocolatey 安装文件的完整路径是 c:\tools\cmdermini\config\user_profile.ps1)中:

function checkGit() {}


2
是的,这就是我要找的答案。如果您可以将代码块从<quote>更改为<code>,那会更好。您可以通过在每行代码前添加4个空格来实现此操作。为了方便起见,请使用<# ... #>(powershell风格注释块)代替# - Kyan
1
谢谢!这让我疯了数月。 - Kieron
不必完全禁用posh-git,您也可以使用$GitPromptSettings.EnableFileStatus = $false来关闭每个提示的git status检查,而不会失去大多数选项卡扩展。 - dahlbyk

6
您的CommandNotFoundException是因为Install-Module需要Powershell 3.0或已安装的PSGet。但是,手动安装应该可以解决问题。
请确认文件posh-git.psm1位于$env:PSModulePath中的某个位置。然后重新启动PowerShell并运行Import-Module posh-git。这应该强制它找到该模块。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接