git blame with commit details in emacs
Asked Answered
V

2

68

From emacs, how can I see the details (e.g. commit message) of the commit that last changed the line at point?

I have magit installed.

Valenevalenka answered 17/3, 2013 at 12:8 Comment(0)
V
111

It is not necessary to use magit for this particular operation - vanilla emacs can do it.

(Also, because this uses vc, this should work identically in any version control system that vc supports.)

First, use the vc-annotate command, which is bound to the key sequence C-x v g.

Now, the point should be at the commit id that you are interested in. (If not, you might need to use C-x 1 and/or v so that you can see which line is which, in order to navigate to the right one.) You might be able to see the diff for that file using = now - if you get an error beginning with "cannot diff from any revision prior...", that probably means that this revision created the file (and that's probably a bug in emacs).

The author and date are already visible in the Annotate buffer that vc-annotate produced.

To see the commit message, press l (the letter, not the number 1) in the Annotate buffer. To see what the file looked like at that revision, press f in either the Annotate buffer or the vc-change-log buffer.

Valenevalenka answered 17/3, 2013 at 12:8 Comment(4)
a is the money action -- show blame before that change. Saves me so much time.Quackery
I absolutely love this mode! I don't need to keep switching between the terminal and emacs. +100 if I could!Neolith
Also, output of vc-annotate makes more sense to me than magit-blame-mode.Neolith
While the output format of vc-annotate is in many ways better than that of magit-blame the latter is much faster, which swings it for me.Schlegel
W
47

I'd suggest the use of magit-blame-mode (M-x magit-blame-mode). It provides the information in much nicer manner compared to vc-annotate and is part of the standard magit distribution. You'd probably want to bind it to some keyboard combination to toggle it quickly.

In magit-blame-mode use p and n to navigate between the previous and the next change and RET to see the diff for a particular commit.

Wiencke answered 17/3, 2013 at 14:37 Comment(8)
Ah, I didn't know about that. I find the vc-annotate output (or any traditional blame output) much more readable than this, personally; but it's always good to have alternatives.Nocuous
I feel that the committer names waste far too much real estate in the output of vc-annotate.Wiencke
@BozhidarBatsov press v to hide the details, you still have the age color coded blame.Quackery
I find the output of magit-blame-mode pretty much unreadable in the way it mixes/interleaves code and commit history. Is there a way to get it to show output like vc-annotate (or git blame, or indeed any other readable format where the code is separate from the annotation)?Knish
Actually, magit-blame-mode doesn't have the main useful feature of vc-annotate, its 'A' (annotate at the revision previous to the current line). So that's another reason to prefer vc-annotate at this point, as awesome as magit is otherwise.Knish
How do you change the colorsBrownlee
@Knish use t to toggle the headings in magit. See magit.vc/manual/magit/Blaming.htmlBreastplate
@Knish Actually, it looks like M-x magit-blame will then blame the revision before the one for that line. So it does have the 'A' functionality. Or you can just do b once you are in magit-blame-mode.Underworld

© 2022 - 2024 — McMap. All rights reserved.