Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git blame with commit details in emacs

Tags:

git

emacs

magit

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.

like image 901
Robin Green Avatar asked Mar 17 '13 12:03

Robin Green


People also ask

Does git blame identify a particular commit?

The git blame command is used to know who/which commit is responsible for the latest changes made to a file. The author/commit of each line can also been seen.

How does blame work in Git?

Summary. The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was. The output format of git blame can be altered with various command line options.

What is EMAC Git?

Magit is a complete text-based user interface to Git. It fills the glaring gap between the Git command-line interface and various GUIs, letting you perform trivial as well as elaborate version control tasks with just a couple of mnemonic key presses.


1 Answers

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.

like image 164
Robin Green Avatar answered Sep 27 '22 23:09

Robin Green