21

I have a file, I make some changes. Here how SmartGit shows differences.

smartgit

As you can see it shows where the difference is within the line. It changes background to red color in concrete position. And it's very good. I don't need to spend time to find differences. I immediately see where is the difference.

Now what it looks like in Magit:

enter image description here

As you can see Magit says that the difference was in WHOLE line. It's not showing where the difference is within the line. So I need to find where is the difference manually. I need to do this every time. It's not very comparable. Suppose I have differences in 20 lines. I need to spend a lot of time to find what actually changed. It's not very good.

Can magit show differences at the actual column where the change is? As in SmartGit.

rpluim
  • 4,605
  • 8
  • 22
a_subscriber
  • 3,854
  • 1
  • 17
  • 47

5 Answers5

18

M-x customize-option RET magit-diff-refine-hunk RET

See also the magit-diff-toggle-refine-hunk command, bound to Dt, which you can use to set the behaviour in the current buffer. Use DC-ut to switch on refinement for all hunks in the buffer; otherwise only the refinements for the currently-selected hunk are displayed at any given time (updating as you move between hunks).

To configure the appearance of the 'refined' regions of the diff, use M-x customize-face for the diff-refine-added, diff-refine-changed, and diff-refine-removed faces.

phils
  • 48,657
  • 3
  • 76
  • 115
13

If you want to store that in your config, like me, just add

(setq magit-diff-refine-hunk (quote all))

to your .emacs.d/init.el


This was inspired by phils' answer.

loki
  • 290
  • 3
  • 9
  • documentation: https://magit.vc/manual/magit/Diff-Options.html – Emmanuel Touzery Dec 20 '20 at 18:18
  • I used `(after! magit (setq magit-diff-refine-hunk 'all))` in `config.el` to get it working in Doom. [Credit.](https://github.com/robcsi/dotfiles/blob/600322c74e40990309814dbaadb8b2bbbedb5e02/doom-emacs/.config/doom/config.el#L58) – DharmaTurtle Dec 23 '21 at 00:56
1

For word diffs to work magit needs to be able to use the diff executable.

So make sure that M-x ielm RET (executable-find "diff") RET returns not nil. If it returns nil add the path to the folder containing your diff executable to the exec-path variable with M-x ielm RET (add-to-list 'exec-path "c:/Program Files/Git/usr/bin") RET

Next you need to make sure that magit is actually using that diff executable. For that enter a magit status buffer, hit D and make sure that -x Disallow external diff drivers (--no-ext-diff) is disabled. Otherwise disable it with -x, set it as default with s and then save the defaults with Dw.

After this is done you can use Dt to toggle the magit-diff-refine-hunk option for your current buffer or follow this answer by phils to make this setting more permanent.

FlyingFoX
  • 181
  • 1
  • 2
0

Try ediff-toggle-ignore-case or compare-ignore-case variable. My guess is your diff engine is ignoring case. Might also be in diff options (I'm not sure what are the settings).

manandearth
  • 2,068
  • 1
  • 11
  • 23
0

Very similar to @loki's answer: Use customize-variable with magit-diff-refine-hunk.

Gizmomogwai
  • 101
  • 3