GitBash 未在 Visual Studio Code 中显示为终端选项

Luc*_*hel 8 terminal git-bash visual-studio-code

我试图在 Visual Studio Code 中插入 GitBash 作为一个选项。我的设置如下所示:

"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": {
      "source": "GitBash",
      "path": ["F:\\Code\\Git\\bin\\bash.exe"],
      "icon": "terminal-bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "GitBash"
Run Code Online (Sandbox Code Playgroud)

但是,在最后一行,Visual Studio Code 给出的错误是:

Value is not accepted. Valid values: "PowerShell", "Command Prompt".(1)
The default profile used on Windows. This setting will currently be ignored if either #terminal.integrated.shell.windows# or #terminal.integrated.shellArgs.windows# are set.
Run Code Online (Sandbox Code Playgroud)

我不明白我哪里出错了。

注意:"terminal.integrated.shell.windows"自 2021 年 4 月起已弃用。

Tim*_* G. 9

我相信 Visual Studio Code 使用您的 PATH 变量来查找您的机器上可用的配置文件。我猜你没有在你的 PATH 中设置 Git Bash 的位置。但是,这应该没问题,因为您path在设置中指定了属性。问题是您也在设置该source属性。根据该说明terminal.integrated.profiles.windows的设置,您可以设置source path,而不是两个:

通过终端下拉菜单创建新终端时要显示的 Windows 配置文件。设置为 null 以排除它们,使用该source属性使用默认检测到的配置。或者,设置path和可选args

删除该source属性,看看问题是否解决,您可以在 Visual Studio Code 中打开一个 git bash 终端。

此外,您可能需要在进行这些更改后重新启动 Visual Studio Code。这可能是一个单独的错误,但在terminal.integrated.profiles.windows您重新启动之前,该设置不会检测到任何添加的新配置文件。

  • env中添加了Git、Git\bin、Git\cmd的路径。删除了源并仅提到了路径。重新启动 VS 代码。行为没有改变。“Git Bash”配置文件无法识别。 (3认同)
  • @蒂莫西G。我将“terminal.integrated.profiles.windows”中的配置文件名称更改为“GitBash”而不是“Git Bash”。它开始出现在“选择默认配置文件”列表中。你的评论让我再次审视这个问题。解决。谢谢 :) (3认同)
  • 还是同样的错误。谢谢你 (2认同)
  • @LucianAnghel 尝试在进行此更改后重新启动 VS Code。我注意到这样做后我也会遇到同样的错误,只有重新启动 VS Code 后才能解决。这可能是一个单独的错误。因此,删除“source”,相应设置“terminal.integrated.defaultProfile.windows”,保存,重新启动 VS Code,然后查看它是否有效。 (2认同)
  • @蒂莫西G。是的,谢谢,它起作用了 - >我将“terminal.integrated.profiles.windows”中的配置文件名称更改为“GitBash”而不是“Git Bash” (2认同)

Bas*_*Bas 9

当粘贴到 settings.json 中时,这对我有用:

{
  "terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": [
        "C:\\Program Files (x86)\\Git\\bin\\bash.exe"
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但前提是“GitBash”没有空格。“Git_Bash”也可以,但“Git Bash”不行。

如果您希望“GitBash”成为默认值,请使用以下语法:

{
  "terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": [
        "C:\\Program Files (x86)\\Git\\bin\\bash.exe"
      ]
    }
  },
  "terminal.integrated.defaultProfile.windows": "GitBash"
}
Run Code Online (Sandbox Code Playgroud)


nag*_*agu 6

VS 代码版本 1.57.1​​。

在 env 中添加 Git、Git\bin、Git\cmd 的路径。具有带有源和路径元素的“Git Bash”配置文件。删除了源并只保留了路径。将 defaultProfile 添加为“Git Bash”时出现“不接受值”错误。重新启动 VS Code 没有帮助。

将“Git Bash”更改为“GitBash”(删除了空格)终于对我有用了:

"terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": ["D:\\ProgramFiles\\Git\\bin\\bash.exe"],
      "args": []
    },
    ...
}
"terminal.integrated.defaultProfile.windows": "GitBash"
Run Code Online (Sandbox Code Playgroud)

我不确定空间是否真的是问题所在。因为有一个配置文件“命令提示符”在其名称中带有空格并被识别!!!为了进一步确认这一点,将“PowerShell”更改为“Power Shell”,它也有效。

我不清楚空间仅在“GitBash”配置文件中的重要性。

  • 感谢将名称从“Git Bash”更改为“GitBash”对我有用! (2认同)

小智 6

我有 VS 代码 1.63.2

移除source财产或空间并"Git Bash"没有帮助。但我在他们的官方网站上找到了这个,我注意到该.exe文件本身是在以下位置指定的path

{
  "terminal.integrated.profiles.windows": {
    "My PowerShell": {
      "path": "pwsh.exe",
      "args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "My PowerShell"
}
Run Code Online (Sandbox Code Playgroud)

所以我尝试添加\\bash.exe到设置中的路径并且它有效:

"terminal.integrated.profiles.windows": {
  "GitBash": {
    "path": "D:\\Git\\bin\\bash.exe",
    "icon": "terminal-bash"
  }
},
"terminal.integrated.defaultProfile.windows": "GitBash"
Run Code Online (Sandbox Code Playgroud)


小智 5

对于使用自定义目录进行 git 安装的任何人:它不适用于版本:1.60.2(用户设置)

Win10用户:

  1. 安装或复制 git 到 C:\Program Files
  2. 添加路径变量名称:GIT_HOME_2 变量:C:\Program Files\Git
  3. 双击路径并添加“%GIT_HOME_2%\bin”
  4. 打开 VS Code,您现在应该看到 bash 终端
{
    "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"
        },
       
    },
    "terminal.integrated.env.windows": {
    
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}
Run Code Online (Sandbox Code Playgroud)