Given a modified buffer, how can I diff it with the file backing it on disk to see what I've changed?
Asked
Active
Viewed 7,664 times
35
-
Related/Duplicate: [How to view diff when emacs suggests to recover this file?](http://emacs.stackexchange.com/q/3776/115) – Kaushal Modi Jan 17 '15 at 17:11
-
There has been [the same question](http://unix.stackexchange.com/q/49835/4319) at unix.stackexchange.com, but with less asnwers. – imz -- Ivan Zakharyaschev Jan 24 '15 at 10:00
2 Answers
42
You want the command M-x diff-buffer-with-file. See the manual:
diff-buffer-with-file is an interactive autoloaded compiled Lisp function in `diff.el'.
(diff-buffer-with-file &optional BUFFER)
View the differences between BUFFER and its associated file. This requires the external program
diff
to be in yourexec-path
.
You may also be interested in highlight-changes-mode
which automatically and interactively highlights changes made to the buffer after it was enabled.

PythonNut
- 10,243
- 2
- 29
- 75
-
Along the lines of `highlight-changes-mode` there's also the `diff-hl` package in GNU ELPA. – Stefan Jan 17 '15 at 04:00
-
1Yes, but right now it only works to show diffs between the (saved) buffer and a `vc` revision. I worked on diffing the _buffer_ (as opposed to its backing file) in [diff-hl #33](https://github.com/dgutov/diff-hl/issues/33), but it's blocked on a bug in the Emacs core. – PythonNut Jan 17 '15 at 05:27
-
-
-
1
23
Command ediff-current-file
:
ediff-current-file is an interactive autoloaded Lisp function in
`ediff.el'.
(ediff-current-file)
Start ediff between current buffer and its file on disk.
This command can be used instead of `revert-buffer'. If there is
nothing to revert then this command fails.

Drew
- 75,699
- 9
- 109
- 225
-
5`ediff-current-file` has some benefits over `diff-buffer-with-file` if you want interactive review of changes rather than a plain diff. The interactive review even allows to selectively revert some parts, in case you finally don't want to save them. See also http://emacs.stackexchange.com/a/3778/10614 for a more complete answer. – Stéphane Gourichon Dec 29 '15 at 11:20