One feature that Xcode has which I think is pretty neat is a "Comparison" mode, which continually shows differences between the current buffer and the most recent commit.

Comparison mode

Is there anything like this for Emacs? I don't really care about the simultaneous side-by-side views. Just highlighting the background of any lines that were changed would be a great help.

I know I can always do C-x v =, but it's a static view of one point in time, and only shows the diffs. I want to see my entire file, editable, with the diffs highlighted.


Dmitry Gutov's diff-hl library provides diff-hl-mode, which gives you the fringe highlighting shown in the top window in the following screenshot (with the actual diff displayed in the bottom window for comparison):

diff-hl screenshot

It uses the generic vc functionality in Emacs in order to be VCS-agnostic. The readme says "Tested with Git, Mercurial, Bazaar and SVN. May work with other VC backends, too."

Note that diff-hl-margin-mode can be employed if you're using terminal Emacs rather than GUI Emacs.

By default diff-hl only highlights the differences between the saved file and the repository; but diff-hl-flydiff-mode enables un-saved differences to be highlighted as well, so that you can see the changes while you edit.

Also note the built-in (to standard Emacs) highlight-changes-mode. That doesn't really tackle your problem out-of-the-box, but the highlight-compare-* functions might facilitate a solution.

  • #33 has been resolved.
    – Dmitry
    Sep 30 '15 at 1:16
  • 1
    Dmitry: Indeed -- I've actually been trying it out over the past few days, and I can confirm that this feature works very well :)
    – phils
    Sep 30 '15 at 1:30
  • I'm glad to hear it; it was written by one very patient contributor. Thanks for updating the answer!
    – Dmitry
    Sep 30 '15 at 2:47

You don't specify what version control system you're using, but if it's git, ou can use git-gutter to put an indicator in the margins when a line has been added, deleted or modified. It's available in MELPA via M-x package-install git-gutter.

  • 1
    This looks pretty close to what I was imagining, but it seems like it only updates the gutter when the buffer is saved. I wonder how hard it'd be to integrate with (or otherwise act more like) flymake...
    – Ken
    Dec 31 '14 at 2:42
  • Ditto. This would be even better if it would automatically add + as soon as you make changes rather than wait for pressing all those buttons to save. Jul 27 '20 at 23:43

You should check out Ediff. It can both display diffs and act as a (3-way) merge tool. It lets you easily revert changes, and also highlights refined differences to show you only the parts of each hunk that actually changed.

screenshot of ediff

ediff-revision will let you easily compare against the most recent commit, or any previous commits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.