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] [-L n,m]
11                   [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [--abbrev=<n>]
12                   [<rev> | --contents <file> | --reverse <rev>] [--] <file>
13
14

DESCRIPTION

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

OPTIONS

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

THE PORCELAIN FORMAT

191       In this format, each line is output after a header; the header at the
192       minimum has the first line which has:
193
194       ·   40-byte SHA-1 of the commit the line is attributed to;
195
196       ·   the line number of the line in the original file;
197
198       ·   the line number of the line in the final file;
199
200       ·   on a line that starts a group of lines from a different commit than
201           the previous one, the number of lines in this group. On subsequent
202           lines this field is absent.
203
204       This header line is followed by the following information at least once
205       for each commit:
206
207       ·   the author name ("author"), email ("author-mail"), time
208           ("author-time"), and timezone ("author-tz"); similarly for
209           committer.
210
211       ·   the filename in the commit that the line is attributed to.
212
213       ·   the first line of the commit log message ("summary").
214
215       The contents of the actual line is output after the above header,
216       prefixed by a TAB. This is to allow adding more header elements later.
217
218       The porcelain format generally suppresses commit information that has
219       already been seen. For example, two lines that are blamed to the same
220       commit will both be shown, but the details for that commit will be
221       shown only once. This is more efficient, but may require more state be
222       kept by the reader. The --line-porcelain option can be used to output
223       full commit information for each line, allowing simpler (but less
224       efficient) usage like:
225
226           # count the number of lines attributed to each author
227           git blame --line-porcelain file |
228           sed -n 's/^author //p' |
229           sort | uniq -c | sort -rn
230

SPECIFYING RANGES

232       Unlike git blame and git annotate in older versions of git, the extent
233       of the annotation can be limited to both line ranges and revision
234       ranges. When you are interested in finding the origin for lines 40-60
235       for file foo, you can use the -L option like so (they mean the same
236       thing — both ask for 21 lines starting at line 40):
237
238           git blame -L 40,60 foo
239           git blame -L 40,+21 foo
240
241       Also you can use a regular expression to specify the line range:
242
243           git blame -L '/^sub hello {/,/^}$/' foo
244
245       which limits the annotation to the body of the hello subroutine.
246
247       When you are not interested in changes older than version v2.6.18, or
248       changes older than 3 weeks, you can use revision range specifiers
249       similar to git rev-list:
250
251           git blame v2.6.18.. -- foo
252           git blame --since=3.weeks -- foo
253
254       When revision range specifiers are used to limit the annotation, lines
255       that have not changed since the range boundary (either the commit
256       v2.6.18 or the most recent commit that is more than 3 weeks old in the
257       above example) are blamed for that range boundary commit.
258
259       A particularly useful way is to see if an added file has lines created
260       by copy-and-paste from existing files. Sometimes this indicates that
261       the developer was being sloppy and did not refactor the code properly.
262       You can first find the commit that introduced the file with:
263
264           git log --diff-filter=A --pretty=short -- foo
265
266       and then annotate the change between the commit and its parents, using
267       commit^! notation:
268
269           git blame -C -C -f $commit^! -- foo
270

INCREMENTAL OUTPUT

272       When called with --incremental option, the command outputs the result
273       as it is built. The output generally will talk about lines touched by
274       more recent commits first (i.e. the lines will be annotated out of
275       order) and is meant to be used by interactive viewers.
276
277       The output format is similar to the Porcelain format, but it does not
278       contain the actual lines from the file that is being annotated.
279
280        1. Each blame entry always starts with a line of:
281
282               <40-byte hex sha1> <sourceline> <resultline> <num_lines>
283
284           Line numbers count from 1.
285
286        2. The first time that a commit shows up in the stream, it has various
287           other information about it printed out with a one-word tag at the
288           beginning of each line describing the extra commit information
289           (author, email, committer, dates, summary, etc.).
290
291        3. Unlike the Porcelain format, the filename information is always
292           given and terminates the entry:
293
294               "filename" <whitespace-quoted-filename-goes-here>
295
296           and thus it is really quite easy to parse for some line- and
297           word-oriented parser (which should be quite natural for most
298           scripting languages).
299
300               Note
301               For people who do parsing: to make it more robust, just ignore
302               any lines between the first and last one ("<sha1>" and
303               "filename" lines) where you do not recognize the tag words (or
304               care about that particular one) at the beginning of the
305               "extended information" lines. That way, if there is ever added
306               information (like the commit encoding or extended commit
307               commentary), a blame viewer will not care.
308

MAPPING AUTHORS

310       If the file .mailmap exists at the toplevel of the repository, or at
311       the location pointed to by the mailmap.file or mailmap.blob
312       configuration options, it is used to map author and committer names and
313       email addresses to canonical real names and email addresses.
314
315       In the simple form, each line in the file consists of the canonical
316       real name of an author, whitespace, and an email address used in the
317       commit (enclosed by < and >) to map to the name. For example:
318
319           Proper Name <commit@email.xx>
320
321       The more complex forms are:
322
323           <proper@email.xx> <commit@email.xx>
324
325       which allows mailmap to replace only the email part of a commit, and:
326
327           Proper Name <proper@email.xx> <commit@email.xx>
328
329       which allows mailmap to replace both the name and the email of a commit
330       matching the specified commit email address, and:
331
332           Proper Name <proper@email.xx> Commit Name <commit@email.xx>
333
334       which allows mailmap to replace both the name and the email of a commit
335       matching both the specified commit name and email address.
336
337       Example 1: Your history contains commits by two authors, Jane and Joe,
338       whose names appear in the repository under several forms:
339
340           Joe Developer <joe@example.com>
341           Joe R. Developer <joe@example.com>
342           Jane Doe <jane@example.com>
343           Jane Doe <jane@laptop.(none)>
344           Jane D. <jane@desktop.(none)>
345
346
347       Now suppose that Joe wants his middle name initial used, and Jane
348       prefers her family name fully spelled out. A proper .mailmap file would
349       look like:
350
351           Jane Doe         <jane@desktop.(none)>
352           Joe R. Developer <joe@example.com>
353
354
355       Note how there is no need for an entry for <jane@laptop.(none)>,
356       because the real name of that author is already correct.
357
358       Example 2: Your repository contains commits from the following authors:
359
360           nick1 <bugs@company.xx>
361           nick2 <bugs@company.xx>
362           nick2 <nick2@company.xx>
363           santa <me@company.xx>
364           claus <me@company.xx>
365           CTO <cto@coompany.xx>
366
367
368       Then you might want a .mailmap file that looks like:
369
370           <cto@company.xx>                       <cto@coompany.xx>
371           Some Dude <some@dude.xx>         nick1 <bugs@company.xx>
372           Other Author <other@author.xx>   nick2 <bugs@company.xx>
373           Other Author <other@author.xx>         <nick2@company.xx>
374           Santa Claus <santa.claus@northpole.xx> <me@company.xx>
375
376
377       Use hash # for comments that are either on their own line, or after the
378       email address.
379

SEE ALSO

381       git-annotate(1)
382

GIT

384       Part of the git(1) suite
385
386
387
388Git 1.8.3.1                       11/19/2018                      GIT-BLAME(1)
Impressum