9

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

1 Answer 1

13
  • 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.

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 9, 2019 at 9:38

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.