This answer shows how to see the differences between a specific file foo.bar in two different branches in git. My question is how to do this within magit?
-
3You can always issue a git command from the magit status buffer by typing `:` (e.g.: `: diff mybranch master -- myfile.cs`) – phils May 04 '13 at 02:52
3 Answers
I use magit to complement vc. vc already has this functionality C-u C-x v =
- 17,467
- 4
- 47
- 62
-
1
-
2
-
Is there a way to add some (un)folding functionality to the resulting buffer? Like similar to the one available in `*magit-diff*` buffer. – Dror May 15 '13 at 11:50
Just wanted to note that this is now directly possible with magit.
In the Magit status buffer, type d to open up the diff popup.
Then limit the diff to your file of interest with =f and the file name.
Finally, do a diff range r and type in the branch that you want to compare to (one can also type in a specific commit on the same branch, see a similar question).
- 827
- 8
- 14
-
2
-
-
The shortcut has changed to `--`, is that also the case for you? – Dominik Schrempf Oct 13 '22 at 13:44
Building up from @dominik-schrempf answer, it is also (now) possible to select the range of the diff with text selection to go quicker than typing the hashes of the commits.
So a quicker (and more visual) sequence could be :
Start from any Magit buffer with a list of commits
(like any commit log or the recent commits list in the Magit status buffer) :Select the commits using text selection
1a. Have the cursor on one end of the wanted commits
1b. Toggle text selection
C-SPC(orVif you use evil-mode)1c. Move your cursor over to the other end of the wanted commits
dto open the diff popupdto open the dwim buffer orrfor diff range (They do mostly the same thing in this case, I think)
For the text selection part, it is the set-mark-command function of Emacs.
You can learn more about it by using Emacs' integrated help system:
C-h ffollowedset-mark-command, or;- from the
execute-extended-command
(which should be your second best friend after the help prefix keyC-hseen above)
M-xfollowed bydescribe-functionfollowed byset-mark-command.
These two paths are equivalent as every Emacs keybindings is calling a function.
In short, use the help prefix and the execute-extended-command often, especially when starting using Emacs.
- 757
- 7
- 6
-
1Could you elaborate on "Select the commits"? In the log, under Recent commits? I always see just the diff for the commit under the pointer. – ericP May 18 '21 at 13:51
-
Just added some more precise informations. ^^ Let me know if this answers your questions, and if I have some more modifications that could be helpful. I'm not quite sure how to add more though without getting out of scope of the question, but more in-depth information about the non-magit emacs specifics can be found at (Mastering Emacs)[https://www.masteringemacs.org/article/mastering-key-bindings-emacs] and (Ergoemacs)[http://ergoemacs.org/emacs/emacs_esoteric.html]. Happy Hacking :) – Raphaël Duchaîne May 27 '21 at 00:53