13

Since ediff-files and ediff-buffers result in apply: Searching for program: no such file or directory, diff error on windows machines.

How to compare two files using Emacs on a windows system?

sturgman
  • 131
  • 6
Empty_Mind
  • 1,341
  • 12
  • 27
  • 1
    By installing GetGnuWin32, you have access to a lot of gnu software (diff but alos wget, sed…). If you only care for diff, you could go with https://www.gnu.org/software/diffutils/ – fredtantini Jun 03 '15 at 07:36
  • The error message tells you what's wrong: You don't have `diff` installed. Go get [Cygwin](https://cygwin.com) and try again. – itsjeyd Jun 03 '15 at 07:37
  • @itsjeyd Cygwin is already installed on system – Empty_Mind Jun 03 '15 at 07:49
  • @fredtantini After installing GetGnuWin32 i get the same error – Empty_Mind Jun 03 '15 at 08:06
  • 2
    Is it in your path? I think the directory should at least be on the `exec-path` variable. – fredtantini Jun 03 '15 at 08:27
  • @Empty_Mind you need the package `diffutils` installed. – nanny Jun 03 '15 at 15:13
  • @nanny is it emacs mode, standalone binary for windows, something i have install in Cygwin or GetGnuWin32? – Empty_Mind Jun 03 '15 at 15:23
  • @Empty_Mind Sorry, I mean the Cygwin package. – nanny Jun 03 '15 at 16:03
  • Mingw on windows provides a minimal environment with Unix utile, including diff. Works like a charm; less overhead than Cygwin. – InHarmsWay Jun 05 '15 at 12:53
  • When I altered my PATH to include a /bin directory that had diff.exe in it, M-x diff started working in Emacs. – Bill Drissel Feb 05 '16 at 04:24
  • I'd never heard of GetGnuWin32 (which seems to be a useful thing: a package manager for the GnuWin32 collection), but I can confirm that installing the DiffUtils package from GnuWin32 worked for me. http://gnuwin32.sourceforge.net/packages/diffutils.htm – Omar Jul 23 '17 at 07:54

5 Answers5

10

As @nanny said in comments, solution is having installed Cygwin with diffutils. Here is how to do it:

  1. Download Cygwin from its homepage.
  2. Install Cygwin with diffutils: A GNU collection of diff utilities package. This package can be found in Utils section in one of few steps of Cygwin installation. installing Cygwin with diffutils
  3. Add Cygwin directories to the PATH windows system variable. This could be done by:
    a) adding your own CYGWIN variable, to keep the order. creating CYGWIN system variable;
    b) and adding variable you just created to the system PATH variable.adding CYGWIN variable to PATH system variable

After this you are able to call ediff-buffers, ediff-files and others successfully. Which looks something like this:running ediff

Enjoy!

Empty_Mind
  • 1,341
  • 12
  • 27
7

If you have git for windows installed, then it is enough to add

C:\Program Files\Git\usr\bin\

to your PATH, because it already ships with a diff executable and installs it in that folder.

FlyingFoX
  • 181
  • 1
  • 2
3

This may save people some time so I will answer here. If you do not wish to add the cygwin bin directory to your path (or any of the other ones suggested in the other answers), you can set the path of the program ediff uses by setting the variable ediff-diff-program. For example you could set it to C:\cygwin\bin (or whatever the actual path is in your case) if using cygwin. It took me some time to figure out which variable to set. Some that DID NOT work were: ediff-custom-diff-program and diff-command.

For example:

(setq ediff-diff-program "c:/CYGWIN64/bin/diff.exe")

does it.

Vrokipal
  • 115
  • 4
sturgman
  • 131
  • 6
  • IIRC, you can't call cygwin binaries outside of the shell, because they fail to load some libraries. I think this will only work when Emacs is run from Cygwin, which should have the `PATH` variable set correctly. Correct me if I'm wrong. –  May 29 '19 at 16:07
  • 1
    @DoMiNeLa10 I tested it on a Windows 10 machine with Emacs 26.1 by starting emacs from the taskbar without knowing about Cygwin... works fine. In addition, the solution adding it to the path would have the same issue you describe if it were really an issue. – sturgman May 29 '19 at 16:46
  • 1
    I am sorry, the last part of my comment is incorrect. Adding it to the path would not have the same issue you suggest, since it would be able to find the libraries. That said, I tested the approach in the answer and it works well. – sturgman May 30 '19 at 11:54
1

If you use the command line installer https://scoop.sh/ you can get diff by typing scoop install diffutils in your prompt.

Cesc
  • 289
  • 1
  • 11
0

If you don't need to produce a diff, but just want to find the differences between the files, one way to do it is to use M-x compare-windows instead.

Open the two files such that you see both of them at the same time, move point to the beginning in both buffers, and run M-x compare-windows. It will move point to the first place where the files differ. This should work without any external executable.

legoscia
  • 6,012
  • 29
  • 54