VSCode as Git editor on Windows Subsystem for linux (WSL)



上下文

系统信息 (视窗(

OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.17134 N/A Build 17134
...
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~3696 Mhz
BIOS Version:              American Megatrends Inc. 2.20, 10/27/2017

系统信息 (WSL(

OS: Debian
Kernel: x86_64 Linux 4.4.0-17134-Microsoft
Shell: zsh 5.3.1
CPU: Intel Core i7-8700K CPU @ 3.696GHz
RAM: 8041MiB / 16344MiB

吉特

~/.gitconfig里有这个:

[core]
editor = code --wait

问题:

当我运行git commit时,vscode 以C:mnt$PathToRepo$.gitCOMMIT_EDITMSG开头,但这个文件是空的(它应该有要提交的更改 + 差异(。

当我写一条提交消息,保存并退出时,我在终端中得到这个:

Aborting commit due to empty commit message.

当我这样做时:

  1. 运行git commit;

  2. 在 vscode 中写入提交消息(例如:初始化存储库(,保存并关闭;

  3. Aborting commit due to empty commit message.后,我再次跑git commit;

VSCode 将以我在步骤 2 中编写的相同提交消息打开(即:初始化存储库(

如果重点是在 vscode 上使用 WSL git,这里是官方解决方案:https://code.visualstudio.com/docs/remote/wsl。

实质上,您只需要安装远程开发扩展包。

目前,VSCode 可以通过利用在 WSL 中运行的vscode-server用作 Git 编辑器。若要对其进行配置,只需将以下行添加到 WSL 中的~/.gitconfig文件中:

[core]
editor = code --wait

如果仍然不起作用,请确保您的vscode-server已添加到环境变量中。在 shell 中运行which code,它应该给出这样的输出

/home/user/.vscode-server/bin/4cb974a7aed77a74c7813bdccd99ee0d04901215/bin/remote-cli/code

vscode-server也适用于远程 Linux 实例。感谢卡罗尔·兹洛特

在尝试更多事情时,此解决方案有效:https://github.com/Microsoft/vscode/issues/27101#issuecomment-306994732

整个问题是为Windows翻译文件的位置。 使用带有包装器脚本的脚本(例如链接到那里的脚本 (https://github.com/Milly/wslpath( 将允许消息在 vscode 中正确打开。 我个人在我的包装脚本中删除了 -n 选项,因为我更喜欢制表符。

最新更新