【问题标题】:GitBash not showing up as a terminal option in Visual Studio CodeGitBash 未在 Visual Studio Code 中显示为终端选项
【发布时间】:2021-09-05 03:37:19
【问题描述】:

我正在尝试将 GitBash 作为选项插入 Visual Studio Code。我的设置如下所示:

"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 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.

我不明白我哪里出错了。

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

【问题讨论】:

    标签: visual-studio-code terminal git-bash


    【解决方案1】:

    我相信 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 设置在您重新启动之前不会检测到任何新添加的配置文件。

    【讨论】:

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

    VS Code 版本 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"
    

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

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

    【讨论】:

    • 感谢从“Git Bash”更改名称->“GitBash”为我工作!
    • @ShrijanRegmi 您也可以将名称更改为“Git Bash”->“Git bash”。这个有效。我认为它的第二个单词应该以小写字母开头。
    【解决方案3】:

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

    Win10 用户:

    1. 在 C:\Program Files 中安装或复制 git
    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"
    }
    

    【讨论】:

    • 确实在默认位置安装了 git,一切恢复正常。
    • 如果我将Git安装在不同的高清中可以吗?
    【解决方案4】:

    我也有这个问题。删除 git bash 的“源”行为我修复了它

    (对不起 Timothy G,这是我试图回答你的建议)

    【讨论】:

      【解决方案5】:

      我遇到了类似的问题。作为蒂莫西。 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", 
      

      【讨论】:

        【解决方案6】:

        这对我有用:

        "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"
            }
          }
        

        【讨论】:

        • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
        【解决方案7】:

        删除对我有用的路径中的括号

        【讨论】:

        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
        【解决方案8】:

        我有 VS Code 1.63.2

        删除source 属性或"Git Bash" 中的空格没有帮助。但是我在他们的官方网站上找到了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"
        

        【讨论】:

          【解决方案9】:

          解决方案是删除 git 并将其重新安装到 默认位置,即 (C:\Program Files\Git)。所有其他 hack 都失败了。

          【讨论】:

            猜你喜欢
            • 2018-03-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-04-16
            • 1970-01-01
            • 2018-02-16
            • 1970-01-01
            • 2017-09-15
            相关资源
            最近更新 更多