Most useful variations of git blame
, using examples from Linux kernel source.
From man git-annotate
:
The only difference between this command and git-blame(1) is that they use slightly different output formats, and this command exists only for backward compatibility to support existing scripts, and provide a more familiar command name for people coming from other SCM systems.
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 bfeffd1552837 (Linus Torvalds 2019-01-06 17:08:20 -0800 2) VERSION = 5 bfeffd1552837 (Linus Torvalds 2019-01-06 17:08:20 -0800 3) PATCHLEVEL = 0 55922c9d1b84b (Linus Torvalds 2011-05-29 17:43:36 -0700 4) SUBLEVEL = 0 d13937116f1e8 (Linus Torvalds 2019-02-10 14:42:20 -0800 5) EXTRAVERSION = -rc6 2e6e902d18502 (Linus Torvalds 2018-11-25 14:19:31 -0800 6) NAME = Shy Crocodile ^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 ...
You can also use -L
for line limiting:
$ git blame -L 1420,1430 Makefile 433db3e260bc8 (Vinícius Tinti 2017-04-24 13:04:58 -0700 1420) @echo ' (requires compiler support for LLVM assembly generation)' 6271897978072 (Joe Perches 2010-01-13 09:31:44 -0800 1421) @echo ' dir/file.lst - Build specified mixed source/assembly target only' 6271897978072 (Joe Perches 2010-01-13 09:31:44 -0800 1422) @echo ' (requires a recent binutils and recent build (System.map))' 155ad605b3c9c (Sam Ravnborg 2005-07-07 17:56:08 -0700 1423) @echo ' dir/file.ko - Build module including final link' (oh, look ...) c4d5ee67ce265 (Robert P. J. Day 2009-04-24 12:35:23 -0400 1424) @echo ' modules_prepare - Set up for building external modules' ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 1425) @echo ' tags/TAGS - Generate tags file for editors' ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 1426) @echo ' cscope - Generate cscope index' f4ed1009fcea8 (Jianbin Kang 2011-01-14 20:07:05 +0800 1427) @echo ' gtags - Generate GNU GLOBAL index' 3f1d9a6cec011 (Michal Marek 2014-07-11 15:57:24 +0200 1428) @echo ' kernelrelease - Output the release version string (use with make -s)' 3f1d9a6cec011 (Michal Marek 2014-07-11 15:57:24 +0200 1429) @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' 3f1d9a6cec011 (Michal Marek 2014-07-11 15:57:24 +0200 1430) @echo ' image_name - Output the image name (use with make -s)' $
Once you determine the offending line, you can examine its encompassing commit with git show
:
$ git show c4d5ee67ce265 commit c4d5ee67ce26503d7eaf2aca5bb13c58e89d1be8 Author: Robert P. J. Day <rpjday@crashcourse.ca> Date: Fri Apr 24 12:35:23 2009 -0400 kbuild: "make prepare" should be "make modules_prepare" Correct the Makefile help text to read "make modules_prepare". Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca> Signed-off-by: Sam Ravnborg <sam@ravnborg.org> diff --git a/Makefile b/Makefile index b309fca4b944..b18afad2e100 100644 --- a/Makefile +++ b/Makefile @@ -1293,7 +1293,7 @@ help: @echo ' dir/ - Build all files in dir and below' @echo ' dir/file.[ois] - Build specified target only' @echo ' dir/file.ko - Build module including final link' - @echo ' prepare - Set up for building external modules' + @echo ' modules_prepare - Set up for building external modules' @echo ' tags/TAGS - Generate tags file for editors' @echo ' cscope - Generate cscope index' @echo ' kernelrelease - Output the release version string'
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.
From man git-config
:
blame.blankBoundary Show blank commit object name for boundary commits in git- blame(1). This option defaults to false. blame.coloring This determines the coloring scheme to be applied to blame output. It can be repeatedLines, highlightRecent, or none which is the default. blame.date Specifies the format used to output dates in git-blame(1). If unset the iso format is used. For supported values, see the discussion of the --date option at git-log(1). blame.showEmail Show the author email instead of author name in git- blame(1). This option defaults to false. blame.showRoot Do not treat root commits as boundaries in git-blame(1). This option defaults to false.