【问题标题】:VSCode error in settings when trying to set Git Bash as default profile for terminal尝试将 Git Bash 设置为终端的默认配置文件时,设置中出现 VSCode 错误
【发布时间】:2021-09-18 18:34:43
【问题描述】:

我尝试将 Git Bash 设置为 VSCode 中的默认终端,但无法成功。我已尝试关注下一篇文章:

  1. How do I use Bash on Windows from the Visual Studio Code integrated terminal?
  2. How to Add Git Bash to VsCode

但他们还没有解决我的问题。

我设法在settings.json 中生成了配置文件,但由于我不知道的某种原因,Git Bash 无法工作,并且 VsCode 显示错误。

我的settings.json

{
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash",
            "path": "C:\\git-sdk-64\\git-bash.exe",
            "args": [
                "--login",
                "-i"
            ]
        },
        "Cygwin": {
            "path": "C:\\cygwin64\\bin\\bash.exe",
            "args": [
                "--login"
            ]
        }
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}

错误:

有谁知道如何解决这个问题?

我的 VsCode 版本:

Version: 1.57.1 (user setup)
Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48
Date: 2021-06-17T13:28:07.755Z
Electron: 12.0.7
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.19042

编辑:

我使用git SDK,它类似于 git-bash,但不完全一样。也许这就是问题所在?

【问题讨论】:

  • 在进行这些更改后尝试完全重新启动 VS Code。我在previous answer 中发现我需要这样做才能让 VS Code 获取新添加的配置文件。
  • @TimothyG。在我的情况下,VsCode 重启没有帮助。

标签: windows visual-studio-code windows-10 vscode-settings git-bash


【解决方案1】:

我刚刚遇到了同样的问题。我的 VS Code 1.60.0 上的解决方案也是将Git Bash 重命名为GitBash

在使用开发者工具进行调试时,我发现 VS Code 总是将对象值与同一个键的默认值“合并”,所以:

  • 在 VS Code 中,Git Bash 键的默认值为 { source: "Git Bash" }
  • 我曾经写过{..., "Git Bash": { "path": "D:\\Git\\usr\\bin\\bash.exe", ... }}
  • 然后合并后的值为{..., "Git Bash": { "source": "Git Bash", "path": "...", ... }}
  • 在名为showProfileQuickPick 的函数期间,VS Code 调用_detectProfiles
    • 此函数将terminal.integrated.profiles.windowsterminal.integrated.defaultProfile.windows 的值发送到其_primaryOffProcessTerminalService
    • profiles 的值只是合并后的值
  • 因此,Git Bash 的对象在某种程度上是“非法的”,然后被忽略了

相反,GitBash 表示声明一个新的配置文件对象,所以它应该可以工作。

【讨论】:

  • 这对我有用。我记得以前没用过。自从我发帖后,VSCode 更新了几次,现在我有了 1.60.0 版本。我还从 settings.json 中删除了 'source: "Git Bash"'。
【解决方案2】:

这终于对我有用了

"terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "GitBash": {
            "path": ["C:\\Program Files\\Git\\bin\\bash.exe"],
            "args": [],
            "icon": "terminal-bash"
        }
    },
    "terminal.integrated.defaultProfile.windows": "GitBash"
}

【讨论】:

  • 现在可以了。也许对 1.60.0 的更新修复了这个特定问题。
  • 将空数组提供给 args 解决了我的问题。谢谢。
猜你喜欢
  • 2021-05-12
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多