1GIT-BLAME(1)                      Git Manual                      GIT-BLAME(1)
2
3
4

NAME

6       git-blame - Show what revision and author last modified each line of a
7       file
8

SYNOPSIS

10       git blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]
11                   [-L <range>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
12                   [--progress] [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>..<rev>]
13                   [--] <file>
14
15

DESCRIPTION

17       Annotates each line in the given file with information from the
18       revision which last modified the line. Optionally, start annotating
19       from the given revision.
20
21       When specified one or more times, -L restricts annotation to the
22       requested lines.
23
24       The origin of lines is automatically followed across whole-file renames
25       (currently there is no option to turn the rename-following off). To
26       follow lines moved from one file to another, or to follow lines that
27       were copied and pasted from another file, etc., see the -C and -M
28       options.
29
30       The report does not tell you anything about lines which have been
31       deleted or replaced; you need to use a tool such as git diff or the
32       "pickaxe" interface briefly mentioned in the following paragraph.
33
34       Apart from supporting file annotation, Git also supports searching the
35       development history for when a code snippet occurred in a change. This
36       makes it possible to track when a code snippet was added to a file,
37       moved or copied between files, and eventually deleted or replaced. It
38       works by searching for a text string in the diff. A small example of
39       the pickaxe interface that searches for blame_usage:
40
41           $ git log --pretty=oneline -S'blame_usage'
42           5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
43           ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
44
45

OPTIONS

47       -b
48           Show blank SHA-1 for boundary commits. This can also be controlled
49           via the blame.blankboundary config option.
50
51       --root
52           Do not treat root commits as boundaries. This can also be
53           controlled via the blame.showRoot config option.
54
55       --show-stats
56           Include additional statistics at the end of blame output.
57
58       -L <start>,<end>, -L :<funcname>
59           Annotate only the given line range. May be specified multiple
60           times. Overlapping ranges are allowed.
61
62           <start> and <end> are optional. “-L <start>” or “-L <start>,” spans
63           from <start> to end of file. “-L ,<end>” spans from start of file
64           to <end>.
65
66           <start> and <end> can take one of these forms:
67
68           ·   number
69
70               If <start> or <end> is a number, it specifies an absolute line
71               number (lines count from 1).
72
73           ·   /regex/
74
75               This form will use the first line matching the given POSIX
76               regex. If <start> is a regex, it will search from the end of
77               the previous -L range, if any, otherwise from the start of
78               file. If <start> is “^/regex/”, it will search from the start
79               of file. If <end> is a regex, it will search starting at the
80               line given by <start>.
81
82           ·   +offset or -offset
83
84               This is only valid for <end> and will specify a number of lines
85               before or after the line given by <start>.
86
87           If “:<funcname>” is given in place of <start> and <end>, it is a
88           regular expression that denotes the range from the first funcname
89           line that matches <funcname>, up to the next funcname line.
90           “:<funcname>” searches from the end of the previous -L range, if
91           any, otherwise from the start of file. “^:<funcname>” searches from
92           the start of file.
93
94       -l
95           Show long rev (Default: off).
96
97       -t
98           Show raw timestamp (Default: off).
99
100       -S <revs-file>
101           Use revisions from revs-file instead of calling git-rev-list(1).
102
103       --reverse <rev>..<rev>
104           Walk history forward instead of backward. Instead of showing the
105           revision in which a line appeared, this shows the last revision in
106           which a line has existed. This requires a range of revision like
107           START..END where the path to blame exists in START.  git blame
108           --reverse START is taken as git blame --reverse START..HEAD for
109           convenience.
110
111       -p, --porcelain
112           Show in a format designed for machine consumption.
113
114       --line-porcelain
115           Show the porcelain format, but output commit information for each
116           line, not just the first time a commit is referenced. Implies
117           --porcelain.
118
119       --incremental
120           Show the result incrementally in a format designed for machine
121           consumption.
122
123       --encoding=<encoding>
124           Specifies the encoding used to output author names and commit
125           summaries. Setting it to none makes blame output unconverted data.
126           For more information see the discussion about encoding in the git-
127           log(1) manual page.
128
129       --contents <file>
130           When <rev> is not specified, the command annotates the changes
131           starting backwards from the working tree copy. This flag makes the
132           command pretend as if the working tree copy has the contents of the
133           named file (specify - to make the command read from the standard
134           input).
135
136       --date <format>
137           Specifies the format used to output dates. If --date is not
138           provided, the value of the blame.date config variable is used. If
139           the blame.date config variable is also not set, the iso format is
140           used. For supported values, see the discussion of the --date option
141           at git-log(1).
142
143       --[no-]progress
144           Progress status is reported on the standard error stream by default
145           when it is attached to a terminal. This flag enables progress
146           reporting even if not attached to a terminal. Can’t use --progress
147           together with --porcelain or --incremental.
148
149       -M[<num>]
150           Detect moved or copied lines within a file. When a commit moves or
151           copies a block of lines (e.g. the original file has A and then B,
152           and the commit changes it to B and then A), the traditional blame
153           algorithm notices only half of the movement and typically blames
154           the lines that were moved up (i.e. B) to the parent and assigns
155           blame to the lines that were moved down (i.e. A) to the child
156           commit. With this option, both groups of lines are blamed on the
157           parent by running extra passes of inspection.
158
159           <num> is optional but it is the lower bound on the number of
160           alphanumeric characters that Git must detect as moving/copying
161           within a file for it to associate those lines with the parent
162           commit. The default value is 20.
163
164       -C[<num>]
165           In addition to -M, detect lines moved or copied from other files
166           that were modified in the same commit. This is useful when you
167           reorganize your program and move code around across files. When
168           this option is given twice, the command additionally looks for
169           copies from other files in the commit that creates the file. When
170           this option is given three times, the command additionally looks
171           for copies from other files in any commit.
172
173           <num> is optional but it is the lower bound on the number of
174           alphanumeric characters that Git must detect as moving/copying
175           between files for it to associate those lines with the parent
176           commit. And the default value is 40. If there are more than one -C
177           options given, the <num> argument of the last -C will take effect.
178
179       -h
180           Show help message.
181
182       -c
183           Use the same output mode as git-annotate(1) (Default: off).
184
185       --score-debug
186           Include debugging information related to the movement of lines
187           between files (see -C) and lines moved within a file (see -M). The
188           first number listed is the score. This is the number of
189           alphanumeric characters detected as having been moved between or
190           within files. This must be above a certain threshold for git blame
191           to consider those lines of code to have been moved.
192
193       -f, --show-name
194           Show the filename in the original commit. By default the filename
195           is shown if there is any line that came from a file with a
196           different name, due to rename detection.
197
198       -n, --show-number
199           Show the line number in the original commit (Default: off).
200
201       -s
202           Suppress the author name and timestamp from the output.
203
204       -e, --show-email
205           Show the author email instead of author name (Default: off). This
206           can also be controlled via the blame.showEmail config option.
207
208       -w
209           Ignore whitespace when comparing the parent’s version and the
210           child’s to find where the lines came from.
211
212       --abbrev=<n>
213           Instead of using the default 7+1 hexadecimal digits as the
214           abbreviated object name, use <n>+1 digits. Note that 1 column is
215           used for a caret to mark the boundary commit.
216

THE PORCELAIN FORMAT

218       In this format, each line is output after a header; the header at the
219       minimum has the first line which has:
220
221       ·   40-byte SHA-1 of the commit the line is attributed to;
222
223       ·   the line number of the line in the original file;
224
225       ·   the line number of the line in the final file;
226
227       ·   on a line that starts a group of lines from a different commit than
228           the previous one, the number of lines in this group. On subsequent
229           lines this field is absent.
230
231       This header line is followed by the following information at least once
232       for each commit:
233
234       ·   the author name ("author"), email ("author-mail"), time
235           ("author-time"), and time zone ("author-tz"); similarly for
236           committer.
237
238       ·   the filename in the commit that the line is attributed to.
239
240       ·   the first line of the commit log message ("summary").
241
242       The contents of the actual line is output after the above header,
243       prefixed by a TAB. This is to allow adding more header elements later.
244
245       The porcelain format generally suppresses commit information that has
246       already been seen. For example, two lines that are blamed to the same
247       commit will both be shown, but the details for that commit will be
248       shown only once. This is more efficient, but may require more state be
249       kept by the reader. The --line-porcelain option can be used to output
250       full commit information for each line, allowing simpler (but less
251       efficient) usage like:
252
253           # count the number of lines attributed to each author
254           git blame --line-porcelain file |
255           sed -n 's/^author //p' |
256           sort | uniq -c | sort -rn
257

SPECIFYING RANGES

259       Unlike git blame and git annotate in older versions of git, the extent
260       of the annotation can be limited to both line ranges and revision
261       ranges. The -L option, which limits annotation to a range of lines, may
262       be specified multiple times.
263
264       When you are interested in finding the origin for lines 40-60 for file
265       foo, you can use the -L option like so (they mean the same thing — both
266       ask for 21 lines starting at line 40):
267
268           git blame -L 40,60 foo
269           git blame -L 40,+21 foo
270
271       Also you can use a regular expression to specify the line range:
272
273           git blame -L '/^sub hello {/,/^}$/' foo
274
275       which limits the annotation to the body of the hello subroutine.
276
277       When you are not interested in changes older than version v2.6.18, or
278       changes older than 3 weeks, you can use revision range specifiers
279       similar to git rev-list:
280
281           git blame v2.6.18.. -- foo
282           git blame --since=3.weeks -- foo
283
284       When revision range specifiers are used to limit the annotation, lines
285       that have not changed since the range boundary (either the commit
286       v2.6.18 or the most recent commit that is more than 3 weeks old in the
287       above example) are blamed for that range boundary commit.
288
289       A particularly useful way is to see if an added file has lines created
290       by copy-and-paste from existing files. Sometimes this indicates that
291       the developer was being sloppy and did not refactor the code properly.
292       You can first find the commit that introduced the file with:
293
294           git log --diff-filter=A --pretty=short -- foo
295
296       and then annotate the change between the commit and its parents, using
297       commit^! notation:
298
299           git blame -C -C -f $commit^! -- foo
300

INCREMENTAL OUTPUT

302       When called with --incremental option, the command outputs the result
303       as it is built. The output generally will talk about lines touched by
304       more recent commits first (i.e. the lines will be annotated out of
305       order) and is meant to be used by interactive viewers.
306
307       The output format is similar to the Porcelain format, but it does not
308       contain the actual lines from the file that is being annotated.
309
310        1. Each blame entry always starts with a line of:
311
312               <40-byte hex sha1> <sourceline> <resultline> <num_lines>
313
314           Line numbers count from 1.
315
316        2. The first time that a commit shows up in the stream, it has various
317           other information about it printed out with a one-word tag at the
318           beginning of each line describing the extra commit information
319           (author, email, committer, dates, summary, etc.).
320
321        3. Unlike the Porcelain format, the filename information is always
322           given and terminates the entry:
323
324               "filename" <whitespace-quoted-filename-goes-here>
325
326           and thus it is really quite easy to parse for some line- and
327           word-oriented parser (which should be quite natural for most
328           scripting languages).
329
330               Note
331               For people who do parsing: to make it more robust, just ignore
332               any lines between the first and last one ("<sha1>" and
333               "filename" lines) where you do not recognize the tag words (or
334               care about that particular one) at the beginning of the
335               "extended information" lines. That way, if there is ever added
336               information (like the commit encoding or extended commit
337               commentary), a blame viewer will not care.
338

MAPPING AUTHORS

340       If the file .mailmap exists at the toplevel of the repository, or at
341       the location pointed to by the mailmap.file or mailmap.blob
342       configuration options, it is used to map author and committer names and
343       email addresses to canonical real names and email addresses.
344
345       In the simple form, each line in the file consists of the canonical
346       real name of an author, whitespace, and an email address used in the
347       commit (enclosed by < and >) to map to the name. For example:
348
349           Proper Name <commit@email.xx>
350
351       The more complex forms are:
352
353           <proper@email.xx> <commit@email.xx>
354
355       which allows mailmap to replace only the email part of a commit, and:
356
357           Proper Name <proper@email.xx> <commit@email.xx>
358
359       which allows mailmap to replace both the name and the email of a commit
360       matching the specified commit email address, and:
361
362           Proper Name <proper@email.xx> Commit Name <commit@email.xx>
363
364       which allows mailmap to replace both the name and the email of a commit
365       matching both the specified commit name and email address.
366
367       Example 1: Your history contains commits by two authors, Jane and Joe,
368       whose names appear in the repository under several forms:
369
370           Joe Developer <joe@example.com>
371           Joe R. Developer <joe@example.com>
372           Jane Doe <jane@example.com>
373           Jane Doe <jane@laptop.(none)>
374           Jane D. <jane@desktop.(none)>
375
376
377       Now suppose that Joe wants his middle name initial used, and Jane
378       prefers her family name fully spelled out. A proper .mailmap file would
379       look like:
380
381           Jane Doe         <jane@desktop.(none)>
382           Joe R. Developer <joe@example.com>
383
384
385       Note how there is no need for an entry for <jane@laptop.(none)>,
386       because the real name of that author is already correct.
387
388       Example 2: Your repository contains commits from the following authors:
389
390           nick1 <bugs@company.xx>
391           nick2 <bugs@company.xx>
392           nick2 <nick2@company.xx>
393           santa <me@company.xx>
394           claus <me@company.xx>
395           CTO <cto@coompany.xx>
396
397
398       Then you might want a .mailmap file that looks like:
399
400           <cto@company.xx>                       <cto@coompany.xx>
401           Some Dude <some@dude.xx>         nick1 <bugs@company.xx>
402           Other Author <other@author.xx>   nick2 <bugs@company.xx>
403           Other Author <other@author.xx>         <nick2@company.xx>
404           Santa Claus <santa.claus@northpole.xx> <me@company.xx>
405
406
407       Use hash # for comments that are either on their own line, or after the
408       email address.
409

SEE ALSO

411       git-annotate(1)
412

GIT

414       Part of the git(1) suite
415
416
417
418Git 2.21.0                        02/24/2019                      GIT-BLAME(1)
Impressum