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

Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder

我想在 cmder powershell 中使用 git。

错误

Cmder 打印出如下错误:

Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder

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

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

我有的东西done/tried

问题

我的 git 命令有效,但没有显示我正在处理的分支。

那我该如何解决呢?

您的 CommandNotFoundException 是因为 Install-Module 需要安装 Powershell 3.0 或 PSGet。但是,手动安装应该可以。

确认文件 posh-git.psm1 位于 $env:PSModulePath 中的某处。然后重新启动 PowerShell 和 运行 Import-Module posh-git。这应该会强制它找到模块。

此答案适用于不需要 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() {}