VSCode:在 Windows 上使用 WSL Git 而不是 Git

VSCode:在 Windows 上使用 WSL Git 而不是 Git

问题描述:

我想在 VSCode 中使用 WSL(Windows 上的 Bash)Git 而不是 Windows 版的 Git,以避免多次安装 Git.

I would like to use WSL (Bash on Windows) Git with VSCode instead of Git for Windows to avoid multiple Git installations.

我创建了一个简单的 bat 脚本,通过在 WSL 中重定向 git 命令来模拟 git.exe 功能.它在 CMD 中运行良好,但不适用于 VSCode.另外,WSL 是我在 VSCode 中的默认终端.

I created a simple bat script to emulate git.exe comportment by redirecting git commands in WSL. It works nicely in CMD but not with VSCode. Also, WSL is my default terminal in VSCode.

VSCode settings.json:

{
    "git.path": "D:\\tools\\git.bat",
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\bash.exe"
}

git.bat:

@echo off
bash -c 'git %*'

有没有让 VSCode 与 WSL Git 一起工作的想法?

Any idea to make VSCode working with WSL Git ?

自 VS Code 1.34(2019 年 4 月)以来,已引入远程扩展以开发到 WSL:https://code.visualstudio.com/docs/remote/wsl.

Since VS Code 1.34 (April 2019) a remote extension has been introduced to develop into WSL: https://code.visualstudio.com/docs/remote/wsl.

基本上,VS Code 的服务器实例启动到 WSL,允许您从 Windows 上的客户端实例使用所有 WSL 工具(例如 git).

Basically, a server instance of VS Code is started into WSL, allowing you to use all the WSL tools (e.g. git) from your client instance on Windows.

感谢您指出这一点 @Noornashriq Masnon