GitBash 未在 Visual Studio 代码中显示为终端选项
GitBash not showing up as a terminal option in Visual Studio Code
我正在尝试将 GitBash 作为选项插入 Visual Studio 代码中。我的设置如下所示:
"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"
然而,在最后一行,Visual Studio代码给出的错误是:
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.
我不明白哪里错了。
注意:"terminal.integrated.shell.windows"
已于 2021 年 4 月弃用。
我相信 Visual Studio 代码使用您的 PATH 变量来查找您的计算机上可用的配置文件。我猜你没有在你的 PATH 中设置 Git Bash 的位置。但是,这应该没问题,因为您在设置中指定了 path
属性。问题是您还设置了 source
属性。根据 terminal.integrated.profiles.windows
设置的描述,您可以设置 source
或 path
,但不能同时设置:
The Windows profiles to present when creating a new terminal via the terminal dropdown. Set to null to exclude them, use the source
property to use the default detected configuration. Or, set the path
and optional args
删除source
属性,看看问题是否解决,您可以在Visual Studio代码中打开一个gitbash终端。
此外,您可能需要在进行这些更改后重新启动 Visual Studio 代码。这可能是一个单独的错误,但 terminal.integrated.profiles.windows
设置在您重新启动之前不会检测到任何添加的新配置文件。
VS 代码版本 1.57.1。
在环境中添加了 Git、Git\bin、Git\cmd 的路径。具有包含源和路径元素的“Git Bash”配置文件。删除源并仅保留路径。将 defaultProfile 添加为“Git Bash”时出现“不接受值”错误。重新启动 VS Code 没有帮助。
将“Git Bash”更改为“GitBash”(space 已删除)终于对我有用:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": ["D:\ProgramFiles\Git\bin\bash.exe"],
"args": []
},
...
}
"terminal.integrated.defaultProfile.windows": "GitBash"
我不确定 space 是否真的是问题所在。因为有一个名称中带有 space 的配置文件“命令提示符”并被识别!!!为了进一步确认这一点,将“PowerShell”更改为“Power Shell”,它也起作用了。
我不清楚 space 仅在“GitBash”配置文件中如何重要。
我遇到了类似的问题。作为蒂莫西。 G 指出,你只能有“来源”或“路径”,不能两者都有。而且,只需重新启动 VS Code 即可启用新创建的配置文件。
这是我创建的默认具有 conda 终端的终端(在 windows 上)
"terminal.integrated.profiles.windows": {
"Conda": {
"path": "C:\windows\System32\cmd.exe",
"args": [
"/K", "C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3"
],
"icon": "squirrel"
}
},
"terminal.integrated.defaultProfile.windows": "Conda",
这对我有用:
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\ProgramFiles\Git\bin\bash.exe"
},
"PowerShell": {
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
}
}
对于使用自定义目录进行 git 安装的任何人:它不适用于版本:1.60.2(用户设置)
Win10 用户:
- 在 C:\Program Files
中安装或复制 git
- 添加路径变量名称:GIT_HOME_2变量:C:\ProgramFiles\Git
- 双击路径并添加“%GIT_HOME_2%\bin”
- 打开 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"
}
删除对我有用的路径中的括号
我有 VS Code 1.63.2
删除 source
属性 或 "Git Bash"
中的 space 没有帮助。但我在他们的官方网站上找到了 this,我注意到 .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"
}
所以我尝试将 \bash.exe
添加到设置中的路径并且成功了:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": "D:\Git\bin\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
解决方案是删除 git 并将其重新安装到 默认位置 ,即 (C:\Program Files\Git)。所有其他黑客都失败了。
- 转到终端 - 新终端打开一个新终端
- 在右边下拉下行-Select Default Profile
- 然后select配置终端配置文件齿轮图标
- 键入需要创建的配置文件的名称,然后按 Enter
- 然后它会打开设置页面并将路径更改为您的
终端路径
在努力解决这个问题之后,我找到了一个简单的解决方案,至少在我没有在默认路径中安装 git 的情况下,是用这个命令制作一个符号 link:
mklink /d "C:\Program Files\Git" "D:\Archivos de Programa\Git"
- /d代表符号link.
- 第一个路径是 link 所在的位置。
- 第二个路径是您的 Git 实际安装的位置。
重新启动后 VSCode,我可以在终端列表中看到 Git Bash 并将其设置为默认值。
粘贴到 settings.json 时对我有用:
{
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": [
"C:\Program Files (x86)\Git\bin\bash.exe"
]
}
}
}
但前提是“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"
}
我正在尝试将 GitBash 作为选项插入 Visual Studio 代码中。我的设置如下所示:
"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"
然而,在最后一行,Visual Studio代码给出的错误是:
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.
我不明白哪里错了。
注意:"terminal.integrated.shell.windows"
已于 2021 年 4 月弃用。
我相信 Visual Studio 代码使用您的 PATH 变量来查找您的计算机上可用的配置文件。我猜你没有在你的 PATH 中设置 Git Bash 的位置。但是,这应该没问题,因为您在设置中指定了 path
属性。问题是您还设置了 source
属性。根据 terminal.integrated.profiles.windows
设置的描述,您可以设置 source
或 path
,但不能同时设置:
The Windows profiles to present when creating a new terminal via the terminal dropdown. Set to null to exclude them, use the
source
property to use the default detected configuration. Or, set thepath
and optionalargs
删除source
属性,看看问题是否解决,您可以在Visual Studio代码中打开一个gitbash终端。
此外,您可能需要在进行这些更改后重新启动 Visual Studio 代码。这可能是一个单独的错误,但 terminal.integrated.profiles.windows
设置在您重新启动之前不会检测到任何添加的新配置文件。
VS 代码版本 1.57.1。
在环境中添加了 Git、Git\bin、Git\cmd 的路径。具有包含源和路径元素的“Git Bash”配置文件。删除源并仅保留路径。将 defaultProfile 添加为“Git Bash”时出现“不接受值”错误。重新启动 VS Code 没有帮助。
将“Git Bash”更改为“GitBash”(space 已删除)终于对我有用:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": ["D:\ProgramFiles\Git\bin\bash.exe"],
"args": []
},
...
}
"terminal.integrated.defaultProfile.windows": "GitBash"
我不确定 space 是否真的是问题所在。因为有一个名称中带有 space 的配置文件“命令提示符”并被识别!!!为了进一步确认这一点,将“PowerShell”更改为“Power Shell”,它也起作用了。
我不清楚 space 仅在“GitBash”配置文件中如何重要。
我遇到了类似的问题。作为蒂莫西。 G 指出,你只能有“来源”或“路径”,不能两者都有。而且,只需重新启动 VS Code 即可启用新创建的配置文件。
这是我创建的默认具有 conda 终端的终端(在 windows 上)
"terminal.integrated.profiles.windows": {
"Conda": {
"path": "C:\windows\System32\cmd.exe",
"args": [
"/K", "C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3"
],
"icon": "squirrel"
}
},
"terminal.integrated.defaultProfile.windows": "Conda",
这对我有用:
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\ProgramFiles\Git\bin\bash.exe"
},
"PowerShell": {
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
}
}
对于使用自定义目录进行 git 安装的任何人:它不适用于版本:1.60.2(用户设置)
Win10 用户:
- 在 C:\Program Files 中安装或复制 git
- 添加路径变量名称:GIT_HOME_2变量:C:\ProgramFiles\Git
- 双击路径并添加“%GIT_HOME_2%\bin”
- 打开 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"
}
删除对我有用的路径中的括号
我有 VS Code 1.63.2
删除 source
属性 或 "Git Bash"
中的 space 没有帮助。但我在他们的官方网站上找到了 this,我注意到 .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"
}
所以我尝试将 \bash.exe
添加到设置中的路径并且成功了:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": "D:\Git\bin\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
解决方案是删除 git 并将其重新安装到 默认位置 ,即 (C:\Program Files\Git)。所有其他黑客都失败了。
- 转到终端 - 新终端打开一个新终端
- 在右边下拉下行-Select Default Profile
- 然后select配置终端配置文件齿轮图标
- 键入需要创建的配置文件的名称,然后按 Enter
- 然后它会打开设置页面并将路径更改为您的 终端路径
在努力解决这个问题之后,我找到了一个简单的解决方案,至少在我没有在默认路径中安装 git 的情况下,是用这个命令制作一个符号 link:
mklink /d "C:\Program Files\Git" "D:\Archivos de Programa\Git"
- /d代表符号link.
- 第一个路径是 link 所在的位置。
- 第二个路径是您的 Git 实际安装的位置。
重新启动后 VSCode,我可以在终端列表中看到 Git Bash 并将其设置为默认值。
粘贴到 settings.json 时对我有用:
{
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": [
"C:\Program Files (x86)\Git\bin\bash.exe"
]
}
}
}
但前提是“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"
}