Using Git in Windows Subsystem for Linux through IntelliJ

前端 未结 9 910
萌比男神i
萌比男神i 2021-01-30 11:10

I\'m trying to set Git executable in IntelliJ to be the git installed in Windows Subsystem for Linux, I tried a few different ways, but always got some sort of error. Today I in

相关标签:
9条回答
  • 2021-01-30 11:38

    I updated the soultion to work with WSL2 with a network drive and PhpStorm 2019.2.

    wsl_git.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 | wsl CURDIR="%cd%"; STR2=${CURDIR//\\//}; STR3=${STR2/U:/}; cd $STR3; git %command%
    
    1. It replaces the path in command for git-commit-msg-.txt to be able to commit as it was mentioned in other answers.

    2. With WSL2 I use the network drive: \\wsl$\<distro_name> -> U:\. My project has path on Windows: U:\home\roman\projects\experiments, but on Linux it is /home/roman/projects/experiments. PhpStorm uses path from Windows to work with git, so it is needed to change path which can be reachable in the Linux subsystem. To achieve this I replace slashes \ -> / (STR2) and remove drive name U: -> `` (STR3) then change current dir to this modified path.

    0 讨论(0)
  • 2021-01-30 11:44

    I was looking for a way to use git on WSL Windows Subsystem for Linux through Webstorm or an IntelliJ idea software.

    I tried KatoPue's solution, but I got the following error:

    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

    I solved it by replacing the path when sending the command to WSL's 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%'
    
    0 讨论(0)
  • 2021-01-30 11:45

    Worked till PHPSTORM 2018.3 (or maybe a Windows Update changed some behavior regarding bash.exe). I am using Ubuntu 18.04 LTS. However, the path of my bash.exe changed - it is no longer in C:\Windows\Sysnative\bash.exe.

    To get things working again I modified Elies Lou's wslgit.bat and set new path for bash.exe:

    @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%'
    
    0 讨论(0)
提交回复
热议问题