通过 IntelliJ 在适用于 Linux 的 Windows 子系统中使用 Git

2024-02-18

我试图将 IntelliJ 中的 Git 可执行文件设置为 Linux 的 Windows 子系统中安装的 git,我尝试了几种不同的方法,但总是遇到某种错误。今天我安装了 Creators Update(版本 1703),重新安装 WSL 并再次尝试,这就是我所做的:

我创建了一个 .bat 脚本:

@echo off
C:\Windows\System32\bash.exe -c "git %*"

所以运行时:

C:\Users\Limon\Desktop>bash.bat --version
git version 2.7.4

So then I tried to set this bat at the git executable in IntelliJ: Setting Git executable in IntelliJ

它成功了!但其他一切都失败了,例如,当我尝试在 IntelliJ 中拉取或分支时,我得到:

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 软件在 WSL Windows Subsystem for Linux 上使用 git 的方法。

我尝试了 KatoPue 的解决方案,但出现以下错误:

fatal: could not read log file 'C:/Program Files/Git/mnt/c/Users/Elies/AppData/Local/Temp/git-commit-msg-.txt': No such file or directory

我通过在将命令发送到 WSL 的 git 时替换路径来解决它

Settings > Version Control > Git > Path to Git executable : path_to_wslgit.bat

wslgit.bat:

@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%'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 IntelliJ 在适用于 Linux 的 Windows 子系统中使用 Git 的相关文章

随机推荐