gpt4 book ai didi

visual-studio-code - VSCode : use WSL Git instead of Git for Windows

转载 作者:行者123 更新时间:2023-12-03 14:10:55 25 4
gpt4 key购买 nike

我想使用 WSL(Windows 上的 Bash)Git 和 VSCode 而不是 Git for Windows 来避免多个 Git 安装。

我创建了一个简单的 bat 脚本来模拟 git.exe通过在 WSL 中重定向 git 命令来实现。它在 CMD 中运行良好,但不适用于 VSCode。此外,WSL 是我在 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 一起工作?

最佳答案

我创建了一个小工具来为自己解决这个问题,并且 hosted it on GitHub .

基本的 git 功能似乎可以工作,例如查看更改和提交。

可以下载现成的二进制文件 from the Releases page .

问题之一是输入路径需要从 Windows 表示( C:\Foo\Bar )转换为 WSL 中的 Linux 路径( /mnt/c/Foo/Bar ),然后再返回到 git 输出中的路径。

比如VSCode中的Git插件使用命令

git rev-parse --show-toplevel

找到 git 存储库的根目录,但是使用 WSL git 这当然会返回一个 Linux 路径,该路径需要为 Windows 上的 VSCode 进行转换。

关于visual-studio-code - VSCode : use WSL Git instead of Git for Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44441830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com