36

Given a modified buffer, how can I diff it with the file backing it on disk to see what I've changed?

nosefrog
  • 805
  • 7
  • 9

3 Answers3

43

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 your exec-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,363
  • 2
  • 30
  • 76
24

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
  • 77,472
  • 10
  • 114
  • 243
  • 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
0

A simple way to achieve this is with the package line-reminder, which shows unsaved and saved changes in current session. You can enable it globally with

(global-line-reminder-mode t)

or on a per-buffer basis with

(line-reminder-mode t)
Dan
  • 32,980
  • 7
  • 102
  • 169
Talespin
  • 109
  • 1