我搜索了网上许多资料,大部分都是用下面这种方法:
#1.安装git
默认安装的情况下,bash.exe的路径为C:\Program Files\Git\bin\。
#2.配置 VS Code 的 setting.json
# 打开( Ctrl+shift+P 快捷键搜索 setting.json)open user setting.json,并添加如下命令,用于强制制定集成终端的shell:
{
"terminal.integrated.profiles.windows": {
"Git Bash": { // 自定义名称
"path": "C:\\Program Files\\Git\\bin\\bash.exe", // git 安装路径
"args": [],
"icon": "terminal-bash" // 该终端的图标
}
},
"terminal.integrated.defaultProfile.windows": "Git Bash", // 设置 Git Bash 为默认终端
}
但是这种方法在我的终端上不成功,我也查看了 git 在 Windows 的环境变量是正确的,找不到原因。
(更新时间 2022-12-13,评论区已有童鞋指出问题原因(自定义名称不能有空格, 应为 GitBash),感谢!)
解决办法:
选择默认配置文件:
点击Windows PowerShell:
在这个文件(setting.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": "G:\\Program Files\\Git\\bin\\bash.exe"
},
"Windows PowerShell": {
"path": "G:\\Program Files\\Git\\bin\\bash.exe" # 把这个路径改为自己的路径即可
}
},
"terminal.integrated.defaultProfile.windows": "Windows PowerShell" # 不能使用自定义的名称,不然一直报错,我也不知道啥原因
}
设置成功,Windows PowerShell 则为 Git Bash:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/74636.html