9

I'd like to do a diff on the current file / buffer compared to the git repository.

Ideally a single function that could be called, or binded to a keyboard shortcut.

0

2 Answers 2

12
  1. Firstly, make sure you're aware of https://stackoverflow.com/a/17799517

  2. If you want a Magit diff buffer for the current file, you can call magit-diff-buffer-file directly, or use the "diff" option (d) in magit-file-popup. e.g.:

    (global-set-key (kbd "C-c m d") 'magit-diff-buffer-file)
    (global-set-key (kbd "C-c m f") 'magit-file-popup)
    
  3. You can alternatively invoke vc-diff with C-xv=

2
  • 1
    (spacemacs/set-leader-keys "gfd" 'magit-diff-buffer-file) A convenient binding for spacemacs. Commented Feb 7, 2019 at 14:59
  • AFAICS, magit-file-popup is no longer available, it's successor (in spirit at least) is magit-file-dispatch.
    – user295
    Commented Sep 30, 2021 at 8:39
5

If you have ediff set up properly (and you should! it's awesome), then you can use M-x ediff-revision to run ediff for the current file against any of its revisions in Git, or in whatever VC system you use.

1
  • ediff-revision is awesome, you can do similar to IntelliJ's git diff on the current file, but perhaps even nicer once you "get it" (make sure to find the little help window by pressing ? to see how you can manipulate the diff, and as usual, to quit press q!).
    – Renato
    Commented Jan 15, 2023 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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