11

I want to see the differences of a file in another branch. With git I can simply do: git diff otherbranch: path-to-file.

In magit this seems trickier as the file may not be dirty and not showing up in magit-status. I have been looking in the manual and I think I need to revert the buffer's minor mode but I have not found how to do this? As a bonus I would also like to ignore whitespaces in my diff.

PS I recently ran a melpa update on my magit package, version is listed below.

magit-annex        20190421.241  available  melpa      Control git-annex from Magit
Drew
  • 75,699
  • 9
  • 109
  • 225
dr jerry
  • 321
  • 1
  • 7

1 Answers1

16
  • Invoke the magit-diff transient (d).
  • Limit to the file you are interested in with the -- option. (Hit tab for completion.)
  • Ignore white space changes with the -w option.
  • Call the magit-diff-range action (r).
  • Select the name of the branch you're interested in. (Hit tab for completion.)

That will diff the branch with the working tree, but you can tweak the range if you're after something else. For example, entering ..<branch> would diff HEAD and the branch.

Kyle Meyer
  • 6,914
  • 26
  • 22
  • 1
    Thanks hat was insightful. 1) l had no idea how to access the switches and options in the transient magit-diff buffer. -2) should have realised that the file's path is to be taken relative to git-root directory. 3) That the range also applies to branches is only meaningful in hindsight. For the rest I also found that, from the buffer containing the file you want to diff, doing `C-c M-g D` prefills the files (Limit to files). – dr jerry Jun 09 '19 at 09:38
  • @drjerry you access switches by pressing `-` then switch name – Ev Dolzhenko May 19 '23 at 13:01