Search code examples
emacsmagit

Emacs Magit: how can I see differences between a given branch and unstaged changes?


With git I can see the differences in a file relative to any other past commit as:

git diff commit file_name

This shows me the differences in file_name between the version in commit against my current unstaged changes.

With Magit I can choose a given commit with . in the log and compare it with another commit with =. However I do not see my unstaged changes in the log so how can I select them to make the comparison?

Thank you in advance.


Solution

  • When in the main magit view (which you get after calling magit-status), you can press d to get a menu of all diff commands. Then press r (range) to diff against a specific commit (which is prompted in the minibuffer).

    If you want the exact equivalent to your git command line and limit the diff to specific files, then press -- before r.

    The complete sequence to get an equivalent of git diff commit file_name is thus :

    • d
    • --file_nameRET
    • rcommitRET