尝试将 Git Bash 设置为终端的默认配置文件时,VSCode 设置中出现错误

a_g*_*irl 7 windows git-bash windows-10 visual-studio-code

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

  1. 如何从 Visual Studio Code 集成终端在 Windows 上使用 Bash?
  2. 如何将 Git Bash 添加到 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"
}
Run Code Online (Sandbox Code Playgroud)

错误:

在此输入图像描述

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

我的 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
Run Code Online (Sandbox Code Playgroud)

编辑:

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

小智 6

这终于对我有用了

"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"
}
Run Code Online (Sandbox Code Playgroud)


Dah*_*ong 2

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

在使用开发工具进行调试期间,我发现 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.windows该函数将和的值发送terminal.integrated.defaultProfile.windows到其_primaryOffProcessTerminalService
    • 的值profiles只是合并后的值
  • 结果, 的对象Git Bash在某种程度上是“非法的”,然后被忽略

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