WSL 1存在一个奇怪的bug, 最早在2019年就提出来了.
在宿主机上通过wsl
命令执行容器内命令的结果会被随机截断, 具体参考这里:
https://youtrack.jetbrains.com/issue/IDEA-242469
这就导致JetBrains系工具无法使用WSL 1内的Git. JetBrains会默认使用宿主机上的Git, 但是如果Git上有commit hook, 就会出现找不到命令的尴尬情况.
但是在上面那个链接里提供了一个简单的trick去解决这个问题:
git.allow.wsl1.executables
, 设置为true
.这个脚本文件还有点意思, 原文给的内容如下:
#!/bin/sh
git "[email protected]"
sleep 0.1 #increase timeout as needed
但是这样做就会无视掉git命令的返回结果, 导致IDE无法判断执行状态.
所以我稍微做了点改动:
#!/bin/sh
git "[email protected]"
EXIT=$? # store the result of git
sleep 0.1 #increase timeout as needed
exit $EXIT # exit as how git exited
完美.
当然, 我建议对将git写为绝对路径, 以防止意外的循环调用.