【问题标题】:Git-Bash in Visual Studio Code from the D drive来自 D 盘的 Visual Studio Code 中的 Git-Bash
【发布时间】:2021-10-12 04:29:07
【问题描述】:

我正在尝试在 Visual Studio Code 中使用 Git Bash 作为终端,但是我无法在终端配置文件中找到它。 Git Bash 的选项不会出现在可用的终端中。我已经安装了 Bash。但是我在D盘中做到了。有没有办法让 git-bash 可以选择作为终端,甚至将其设置为 D 盘中的默认终端?

【问题讨论】:

    标签: visual-studio-code git-bash


    【解决方案1】:

    我也遇到了同样的问题,但在@Timothy G's answer 提供的最后一点帮助以及堆栈上其他帖子的帮助下,我终于解决了这个问题。

    如果您仍在努力解决问题,我将在下面的 @Timothy G's answer JIC 中发布一个分步解决方案,并为未来的访问者提供帮助。

    注意:我在 Windows 上使用 VS Code Insiders 构建(版本:1.64.0-insider(用户设置)),但也适用于其他构建。

    由于你已经下载了 git bash,所以忽略第一步。

    1. https://git-scm.com/download/win 下载 git bash。
    2. 打开 VS Code ⟹ 文件 ⟹ 首选项 ⟹ 设置。 (Ctrl + ,)。

    顶部会有一个搜索栏。

    1. 搜索terminal.integrated.profiles.windows

    会出现如下所示的结果

    终端 › 集成 › 配置文件:Windows

    通过终端下拉菜单创建新终端时要显示的 Windows 配置文件。使用 source 属性自动检测 shell 的位置。或者使用可选参数手动设置路径属性。 将现有配置文件设置为 null 以从列表中隐藏配置文件,例如:“Ubuntu-20.04 (WSL)”:null。

    在 settings.json 中编辑

    1. 点击Edit in settings.json

    然后会在Settings标签旁边弹出另一个窗口,名为settings.json

    1. 复制并粘贴到settings.json 中。请记住在 bin 文件夹中设置 git bash.exe 的“路径”

    如果不需要,可以删除前两行并执行 Ctrl + S 以保存 JSON 设置。

    {
    
        "workbench.colorTheme": "Default Dark+",
        "files.autoSave": "afterDelay",
        
    
        "terminal.integrated.profiles.windows": {
    
    
    
            "My Git Bash":{
                "path": "I:\\Projects\\git\\bin\\bash.exe",
                "icon": "terminal-bash"
            }
    },
    
    "terminal.integrated.defaultProfile.windows": "My Git Bash",
    
    
    
    }
    
    1. 添加以上内容后,再次选择“设置”选项卡,搜索terminal.integrated.defaultProfile.windows

    然后你会看到一个像这样带有下拉菜单的终端功能。

    终端 › 集成 › 默认配置文件:Windows Windows 上使用的默认配置文件。如果设置了 terminal.integrated.shell.windows 或 terminal.integrated.shellArgs.windows,则当前将忽略此设置。

    1. 在下拉列表下,选择配置文件My Git Bash 然后你 一切就绪。
    2. 然后到⟹查看⟹终端。 (Ctrl + `)

    它现在应该显示在 bash 终端中。如果没有,请重新启动 VSC,它肯定会工作。

    【讨论】:

      【解决方案2】:

      您可以在 setting.json 文件中创建自己的配置文件并将默认终端配置文件设置为它,如下所示(对于 Windows):

      "terminal.integrated.profiles.windows": {
              "My Git Bash":{
                  "path": "D:\\GitbashLocation\\git-bash.exe",
                  "icon": "terminal-bash"
              }
      },
      "terminal.integrated.defaultProfile.windows": "My Git Bash",
      
      

      请注意,您可以随意命名您的个人资料。您可能还需要在定义配置文件后重新启动 Visual Studio Code,以便在您在 terminal.integrated.defaultProfile.windows 设置中指定它时检测到它。

      【讨论】:

      • 感谢您的回答。但是,即使这样做了,Git Bash 仍然没有出现在终端选择器中。我拥有的选项是 powershell、cmd 和 javascript 调试器。我还缺少其他配置吗?
      • @Mark 确保您尝试重新启动 VS Code 至少几次。关于这个设置的一些东西是错误的 - 我过去有answered 一个类似的问题并且重新启动工作。还要确保您的路径设置正确。
      • G 尝试了你的建议,不幸的是仍然没有运气。也许它只是越野车。无论如何感谢您的帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 2020-02-27
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 2018-10-21
      相关资源
      最近更新 更多