This is an old revision of the document!


Most useful variations of git blame, using examples from Linux kernel source.

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 ...

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'
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.
  • git_blame.1550407593.txt.gz
  • Last modified: 2019/02/17 12:46
  • by rpjday