Using Git in Windows Subsystem for Linux through IntelliJ
我试图将IntelliJ中的Git可执行文件设置为安装在Linux的Windows子系统中的git,我尝试了几种不同的方法,但始终会遇到某种错误。 今天,我安装了Creators Update(版本1703),重新安装了WSL,然后再次尝试,这是我所做的:
我创建了一个.bat脚本:
1 2 | @echo off C:\\Windows\\System32\\bash.exe -c"git %*" |
因此,在运行它时:
1 2 | C:\\Users\\Limon\\Desktop>bash.bat --version git version 2.7.4 |
因此,然后我尝试在IntelliJ中的git可执行文件上设置此蝙蝠:
而且有效! 但是其他所有操作都失败了,例如,当我尝试在IntelliJ中拉动或分支时,我得到:
1 2 3 | Couldn't check the working tree for unmerged files because of an error. 'C:\\Windows\\System32\\bash.exe' is not recognized as an internal or external command, operable program or batch file. |
有关如何解决此问题的任何想法? 我对批处理脚本一无所知。 它可以在命令行下完美运行。
我一直在寻找一种通过Webstorm或IntelliJ idea软件在Linux的WSL Windows子系统上使用git的方法。
我尝试了KatoPue的解决方案,但出现以下错误:
我通过将命令发送到WSL的git时替换路径来解决它
1 | Settings > Version Control > Git > Path to Git executable : path_to_wslgit.bat |
wslgit.bat:
1 2 3 4 5 6 7 | @echo off setlocal enabledelayedexpansion set command=%* set find=C:\\Users\\%USERNAME%\\AppData\\Local\\Temp\\git-commit-msg-.txt set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt call set command=%%command:!find!=!replace!%% echo | C:\\Windows\\Sysnative\\bash.exe -c 'git %command%' |
在尝试解决Git时,我在PyCharm 2018.1中遇到了各种错误。我必须结合不同的方法来使其运行。下一个代码对我有用:
1 2 3 4 5 6 7 8 | @echo off setlocal enabledelayedexpansion set command=%* If %PROCESSOR_ARCHITECTURE% == x86 ( echo | C:\\Windows\\sysnative\\bash.exe -c 'git %command%' ) Else ( echo | bash.exe -c 'git %command%' ) |
UPD:
现在可以通过WSLGit包装器在WSL中与Git集成。我已经通过PyCharm对其进行了检查,它的工作就像是一种魅力。这是一个链接https://github.com/andy-5/wslgit
将双引号更改为单引号。
您可以登录,哪些参数被输入到bat文件中
1 2 3 | @echo off @echo %*>> %~dp0log.txt bash.exe -c 'git %*' |
这样,我发现自己遇到了一些逃避的问题。
仅供参考:使用Win10创建者更新管道bash并从Windows程序生成它可以正常工作。
由于WebStorm 2020.2 EAP,所以可以。
只需将
要获取
在PhpStorm(2017.2 EAP)中出现错误
Caused by: com.intellij.openapi.vcs.VcsException: 'bash.exe' is not recognized as an internal or external command, operable program or batch file.
对于解决方案,我将最后一行更改为
1 2 3 4 5 | If %PROCESSOR_ARCHITECTURE% == x86 ( C:\\Windows\\sysnative\\bash.exe -c 'git %command%' ) Else ( bash.exe -c 'git %command%' ) |
对我来说,此解决方案有效:
档案:git.bat
1 2 3 4 5 6 7 8 | @echo off setlocal enabledelayedexpansion set command=%* If %PROCESSOR_ARCHITECTURE% == x86 ( C:\\Windows\\sysnative\\bash.exe -c 'git %command%' ) Else ( bash.exe -c 'git %command%' ) |
正如Gabrielizalo先前回答的那样,您需要使用2020.2及更高版本。
-
转到设置|版本控制|吉特
-
将
\\\\wsl$\\YOUR-WSL-VERSION\\usr\\bin\\git 添加到Git可执行文件路径。
请注意,如果使用的是WLinux发行版,则需要使用名称Pengwin。
即使
这就是我
我更新了魂魄,使其可以通过网络驱动器和PhpStorm 2019.2。与WSL2一起使用。
wsl_git.bat:
1 2 3 4 5 6 7 | @echo off setlocal enabledelayedexpansion set command=%* set find=C:\\Users\\%USERNAME%\\AppData\\Local\\Temp\\git-commit-msg-.txt set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt call set command=%%command:!find!=!replace!%% echo | wsl CURDIR="%cd%"; STR2=${CURDIR//\\\\//}; STR3=${STR2/U:/}; cd $STR3; git %command% |
它将
对于WSL2,我使用网络驱动器:
oman\\projects\\experiments
一直工作到PHPSTORM 2018.3(或者Windows Update更改了有关bash.exe的某些行为)。我正在使用Ubuntu 18.04 LTS。但是,我的bash.exe的路径已更改-
为了使事情再次起作用,我修改了Elies Lou的wslgit.bat并为bash.exe设置了新路径:
1 2 3 4 5 6 7 | @echo off setlocal enabledelayedexpansion set command=%* set find=C:\\Users\\%USERNAME%\\AppData\\Local\\Temp\\git-commit-msg-.txt set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt call set command=%%command:!find!=!replace!%% echo | C:\\Windows\\System32\\bash.exe -c 'git %command%' |