4

Using git cli I would execute

git diff SHA#1 SHA#2

How does one do the equivalent in magit?

2 Answers 2

6

Use the diff range command with the .. syntax:

dr SHA#1..SHA#2

Refer to the git diff man page:

   git diff [--options] <commit> <commit> [--] [<path>...]
       This is to view the changes between two arbitrary <commit>.

   git diff [--options] <commit>..<commit> [--] [<path>...]
       This is synonymous to the previous form. If <commit> on one side is omitted,
       it will have the same effect as using HEAD instead.

   git diff [--options] <commit>...<commit> [--] [<path>...]
       This form is to view the changes on the branch containing and up to the second
       <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is
       equivalent to "git diff $(git-merge-base A B) B". You can omit any one of
       <commit>, which has the same effect as using HEAD instead.

Note that you can type both commits with completion (but you have to type the .. before completion for the second kicks in).

1
  • Awesome, thanks! I did work out that one can 'branch'-'check out' ("b")("c") to the later of the two SHAs of interest. Then run 'diff-'Diff range' ("d")("r"), where you can specify the second (earlier) SHA. But being able to specify both SHAs like you have highlighted is perfect.
    – orion
    Oct 4, 2016 at 2:40
5

If both commits are near each other in some Magit buffer, then it might be convenient to mark them using the region and then pressing d d. With such an active region "diff dwim" assumes that you want to compare the commits at the edge of the region.

d r works always. It might just be a bit annoying to type or copy-paste hashes.

1
  • Cool thanks @tarsius. Did not know about this. Well first thing is finding the hash. I was using y when in the logging screen. Useful for big code bases that use version tagging. Allows me to diff between versions. So yes, using this alternate method can be very useful.
    – orion
    Oct 4, 2016 at 22:52

Your Answer

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

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