This is an old revision of the document!
Overview
Most useful variations of git blame, using examples from Linux kernel source.
Basic usage
Show the (most recent) origin of each line in a file:
$ git blame Makefile b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0 c517d838eb7d0 (Linus Torvalds 2015-02-22 18:21:14 -0800 2) VERSION = 4 60cc43fc88842 (Linus Torvalds 2018-04-15 18:24:20 -0700 3) PATCHLEVEL = 17 55922c9d1b84b (Linus Torvalds 2011-05-29 17:43:36 -0700 4) SUBLEVEL = 0 67b8d5c708122 (Linus Torvalds 2018-05-13 16:15:17 -0700 5) EXTRAVERSION = -rc5 75bc37fefc447 (Linus Torvalds 2018-05-06 16:57:38 -1000 6) NAME = Merciless Moray ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7) ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 8) # *DOCUMENTATION* ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9) # To see a list of typical targets execute "make help" ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10) # More info can be located in ./README ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 11) # Comments in this file are targeted only to the developer, do not ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) # expect to learn how to build the kernel reading this file. ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) ... snip ...
and once you determine the offending line, you can examine its encompassing commit with git show:
$ git show b24413180f560
commit b24413180f5600bcb3bb70fbed5cf186b60864bd
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Wed Nov 1 15:07:57 2017 +0100
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
... snip ...
Some useful options
A very small subset of options for git blame (there are far more):
-L <start>,<end>, -L :<funcname>
Annotate only the given line range. May be specified multiple times.
Overlapping ranges are allowed.
-s
Suppress the author name and timestamp from the output.
-e, --show-email
Show the author email instead of author name (Default: off).
This can also be controlled via the ''blame.showEmail'' config option.