Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

batch file - Using Git in Windows Subsystem for Linux through IntelliJ

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 installed to Creators Update (Version 1703), reinstalled WSL and tried again, here's what I did:

I created a .bat script:

@echo off
C:WindowsSystem32ash.exe -c "git %*"

So when running it:

C:UsersLimonDesktop>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

And it worked! But everything else fails, for example when I try to pull or branch in IntelliJ, I get:

Couldn't check the working tree for unmerged files because of an error.
'C:WindowsSystem32ash.exe' is not recognized as an internal or external command,
operable program or batch file.

Any ideas on how fix this? I don't really know anything about batch scripting. It works perfectly off command line.

question from:https://stackoverflow.com/questions/43666009/using-git-in-windows-subsystem-for-linux-through-intellij

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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%AppDataLocalTempgit-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | C:WindowsSysnativeash.exe -c 'git %command%'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...