Problem
Interactive Git operations (squash, rebase, reword) initiated from IntelliJ IDEA fail when the project is located in WSL2. The Git Log action Squash Commits (or any other interactive rebase) returns the following error:
/mnt/c/Program Files/JetBrains/IntelliJ IDEA <version>/jbr/bin/java.exe: Exec format error
error: There was a problem with the editor '/mnt/c/Users/user/AppData/Local/JetBrains/IntelliJIdea<version>/tmp/intellij-git-editor-wsl-<distro>.sh'.
The same error appears in idea.log:
INFO - #git4idea.commands.GitHandler - /mnt/c/Users/user/AppData/Local/JetBrains/IntelliJIdea<version>/tmp/intellij-git-editor-wsl-<distro>.sh: 3: /mnt/c/Program Files/JetBrains/IntelliJ IDEA <version>/jbr/bin/java.exe: Exec format error
INFO - #git4idea.rebase.GitRebaseProcess - Error rebasing root <project>: ...
Cause
This is a known issue in WSL2 when systemd is enabled. The binfmt configuration for running Windows binaries (WSLInterop) is missing the F (fix-binary) flag, so Windows executables such as java.exe cannot be invoked from within the WSL shell. The IntelliJ Git editor script relies on launching java.exe from /mnt/c/..., so the rebase fails.
Reference: microsoft/WSL#8843. The original report indicates a fix in WSL 2.5.1, but the issue still reproduces on later versions (for example, 2.6.3).
Resolution
-
In the affected WSL distribution, create the file
/usr/lib/binfmt.d/WSLInterop.confwith the following content::WSLInterop:M::MZ::/init:PF -
From a Windows terminal, shut down WSL:
wsl --shutdown -
Restart the WSL distribution and IntelliJ IDEA.
After restart, Squash Commits, Interactive Rebase, and Reword complete successfully on projects located inside WSL.
Comments
0 comments
Please sign in to leave a comment.