An old question that got bumped today via an edit. The existing answer probably works, but I can think of two other possibilities as well.
To be clear, the OP was using Windows Subsystem for Linux (WSL) to run Ubuntu in Windows. They had previously been using Git for Windows with kdiff3.exe
, but they wanted to transition the workflow to Linux Git in WSL/Ubuntu.
While you were on the right track with changing the path of the difftool from C:\...
to /mnt/c/...
, there was more to it than that. Since WSL does allow you to run Windows executables this way, it was actually attempting to run the kdiff3.exe
. But since you were (then) using the Linux version of git
, it was naturally using Linux paths for the files to compare.
To expand on what @oikku said in the other answer, since kdiff3.exe
is a Windows executable, it only understands Windows path structures (a.k.a. C:\...
). When Linux git passed it a Linux path, the Windows executable (rightly) choked, giving you the error Opening of these files failed
.
For example:
# What Windows kdiff3 expected:
kdiff3.exe C:\file1.txt.rev1 C:\file1.txt.rev2
# What Windows kdiff3 got from Linux Git:
kdiff3.exe /mnt/c/file1.txt.rev1 /mnt/c/file1.txt.rev2
There are two additional possible solutions, at least today:
First, it should be possible to write a wrapper script around kdiff3.exe
that would do the path translation of the arguments passed to it. You can use the wslpath
command which is (at least now) installed by default in WSL/Ubuntu to do the directory translations. I can't think of any reason why this wouldn't work; you'd just need to make sure you passed through all of the possible arguments from your wrapper script to the command in the form it expects.
Second, you could install the Linux version of Kdiff3, but realize that it requires a GUI, which (at the time of this answer) WSL does not support directly. That means that you would need to install a Windows X server and the X libraries in WSL/Ubuntu. There are plenty of other questions/answers on this topic already across the Stack sites, so I won't repeat them here.
Also note that Windows 11 will include WSLg, a feature that does allow you to use Linux GUI apps under WSL. So that will presumably makes this much easier when that becomes available.