1GIT-BLAME(1) Git Manual GIT-BLAME(1)
2
3
4
6 git-blame - Show what revision and author last modified each line of a
7 file
8
10 git blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [--incremental] [-L n,m]
11 [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
12 [<rev> | --contents <file> | --reverse <rev>] [--] <file>
13
14
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 report does not tell you anything about lines which have been
23 deleted or replaced; you need to use a tool such as git diff or the
24 "pickaxe" interface briefly mentioned in the following paragraph.
25
26 Apart from supporting file annotation, git also supports searching the
27 development history for when a code snippet occurred in a change. This
28 makes it possible to track when a code snippet was added to a file,
29 moved or copied between files, and eventually deleted or replaced. It
30 works by searching for a text string in the diff. A small example:
31
32 $ git log --pretty=oneline -S´blame_usage´
33 5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
34 ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
35
36
38 -b
39 Show blank SHA-1 for boundary commits. This can also be controlled
40 via the blame.blankboundary config option.
41
42 --root
43 Do not treat root commits as boundaries. This can also be
44 controlled via the blame.showroot config option.
45
46 --show-stats
47 Include additional statistics at the end of blame output.
48
49 -L <start>,<end>
50 Annotate only the given line range. <start> and <end> can take one
51 of these forms:
52
53 · number
54
55 If <start> or <end> is a number, it specifies an absolute line
56 number (lines count from 1).
57
58 · /regex/
59
60 This form will use the first line matching the given POSIX
61 regex. If <end> is a regex, it will search starting at the line
62 given by <start>.
63
64 · +offset or -offset
65
66 This is only valid for <end> and will specify a number of lines
67 before or after the line given by <start>.
68
69 -l
70 Show long rev (Default: off).
71
72 -t
73 Show raw timestamp (Default: off).
74
75 -S <revs-file>
76 Use revisions from revs-file instead of calling git-rev-list(1).
77
78 --reverse
79 Walk history forward instead of backward. Instead of showing the
80 revision in which a line appeared, this shows the last revision in
81 which a line has existed. This requires a range of revision like
82 START..END where the path to blame exists in START.
83
84 -p, --porcelain
85 Show in a format designed for machine consumption.
86
87 --incremental
88 Show the result incrementally in a format designed for machine
89 consumption.
90
91 --encoding=<encoding>
92 Specifies the encoding used to output author names and commit
93 summaries. Setting it to none makes blame output unconverted data.
94 For more information see the discussion about encoding in the git-
95 log(1) manual page.
96
97 --contents <file>
98 When <rev> is not specified, the command annotates the changes
99 starting backwards from the working tree copy. This flag makes the
100 command pretend as if the working tree copy has the contents of the
101 named file (specify - to make the command read from the standard
102 input).
103
104 --date <format>
105 The value is one of the following alternatives:
106 {relative,local,default,iso,rfc,short}. If --date is not provided,
107 the value of the blame.date config variable is used. If the
108 blame.date config variable is also not set, the iso format is used.
109 For more information, See the discussion of the --date option at
110 git-log(1).
111
112 -M|<num>|
113 Detect moved or copied lines within a file. When a commit moves or
114 copies a block of lines (e.g. the original file has A and then B,
115 and the commit changes it to B and then A), the traditional blame
116 algorithm notices only half of the movement and typically blames
117 the lines that were moved up (i.e. B) to the parent and assigns
118 blame to the lines that were moved down (i.e. A) to the child
119 commit. With this option, both groups of lines are blamed on the
120 parent by running extra passes of inspection.
121
122 <num> is optional but it is the lower bound on the number of
123 alphanumeric characters that git must detect as moving within a
124 file for it to associate those lines with the parent commit.
125
126 -C|<num>|
127 In addition to -M, detect lines moved or copied from other files
128 that were modified in the same commit. This is useful when you
129 reorganize your program and move code around across files. When
130 this option is given twice, the command additionally looks for
131 copies from other files in the commit that creates the file. When
132 this option is given three times, the command additionally looks
133 for copies from other files in any commit.
134
135 <num> is optional but it is the lower bound on the number of
136 alphanumeric characters that git must detect as moving between
137 files for it to associate those lines with the parent commit.
138
139 -h, --help
140 Show help message.
141
142 -c
143 Use the same output mode as git-annotate(1) (Default: off).
144
145 --score-debug
146 Include debugging information related to the movement of lines
147 between files (see -C) and lines moved within a file (see -M). The
148 first number listed is the score. This is the number of
149 alphanumeric characters detected as having been moved between or
150 within files. This must be above a certain threshold for git blame
151 to consider those lines of code to have been moved.
152
153 -f, --show-name
154 Show the filename in the original commit. By default the filename
155 is shown if there is any line that came from a file with a
156 different name, due to rename detection.
157
158 -n, --show-number
159 Show the line number in the original commit (Default: off).
160
161 -s
162 Suppress the author name and timestamp from the output.
163
164 -w
165 Ignore whitespace when comparing the parent’s version and the
166 child’s to find where the lines came from.
167
169 In this format, each line is output after a header; the header at the
170 minimum has the first line which has:
171
172 · 40-byte SHA-1 of the commit the line is attributed to;
173
174 · the line number of the line in the original file;
175
176 · the line number of the line in the final file;
177
178 · on a line that starts a group of lines from a different commit than
179 the previous one, the number of lines in this group. On subsequent
180 lines this field is absent.
181
182 This header line is followed by the following information at least once
183 for each commit:
184
185 · the author name ("author"), email ("author-mail"), time
186 ("author-time"), and timezone ("author-tz"); similarly for
187 committer.
188
189 · the filename in the commit that the line is attributed to.
190
191 · the first line of the commit log message ("summary").
192
193 The contents of the actual line is output after the above header,
194 prefixed by a TAB. This is to allow adding more header elements later.
195
197 Unlike git blame and git annotate in older versions of git, the extent
198 of the annotation can be limited to both line ranges and revision
199 ranges. When you are interested in finding the origin for lines 40-60
200 for file foo, you can use the -L option like so (they mean the same
201 thing — both ask for 21 lines starting at line 40):
202
203 git blame -L 40,60 foo
204 git blame -L 40,+21 foo
205
206 Also you can use a regular expression to specify the line range:
207
208 git blame -L ´/^sub hello {/,/^}$/´ foo
209
210 which limits the annotation to the body of the hello subroutine.
211
212 When you are not interested in changes older than version v2.6.18, or
213 changes older than 3 weeks, you can use revision range specifiers
214 similar to git rev-list:
215
216 git blame v2.6.18.. -- foo
217 git blame --since=3.weeks -- foo
218
219 When revision range specifiers are used to limit the annotation, lines
220 that have not changed since the range boundary (either the commit
221 v2.6.18 or the most recent commit that is more than 3 weeks old in the
222 above example) are blamed for that range boundary commit.
223
224 A particularly useful way is to see if an added file has lines created
225 by copy-and-paste from existing files. Sometimes this indicates that
226 the developer was being sloppy and did not refactor the code properly.
227 You can first find the commit that introduced the file with:
228
229 git log --diff-filter=A --pretty=short -- foo
230
231 and then annotate the change between the commit and its parents, using
232 commit^! notation:
233
234 git blame -C -C -f $commit^! -- foo
235
237 When called with --incremental option, the command outputs the result
238 as it is built. The output generally will talk about lines touched by
239 more recent commits first (i.e. the lines will be annotated out of
240 order) and is meant to be used by interactive viewers.
241
242 The output format is similar to the Porcelain format, but it does not
243 contain the actual lines from the file that is being annotated.
244
245 1. Each blame entry always starts with a line of:
246
247 <40-byte hex sha1> <sourceline> <resultline> <num_lines>
248
249 Line numbers count from 1.
250
251 2. The first time that a commit shows up in the stream, it has various
252 other information about it printed out with a one-word tag at the
253 beginning of each line describing the extra commit information
254 (author, email, committer, dates, summary, etc.).
255
256 3. Unlike the Porcelain format, the filename information is always
257 given and terminates the entry:
258
259 "filename" <whitespace-quoted-filename-goes-here>
260
261 and thus it is really quite easy to parse for some line- and
262 word-oriented parser (which should be quite natural for most
263 scripting languages).
264
265 Note
266 For people who do parsing: to make it more robust, just ignore
267 any lines between the first and last one ("<sha1>" and
268 "filename" lines) where you do not recognize the tag words (or
269 care about that particular one) at the beginning of the
270 "extended information" lines. That way, if there is ever added
271 information (like the commit encoding or extended commit
272 commentary), a blame viewer will not care.
273
275 If the file .mailmap exists at the toplevel of the repository, or at
276 the location pointed to by the mailmap.file configuration option, it is
277 used to map author and committer names and email addresses to canonical
278 real names and email addresses.
279
280 In the simple form, each line in the file consists of the canonical
281 real name of an author, whitespace, and an email address used in the
282 commit (enclosed by < and >) to map to the name. For example:
283
284 Proper Name <commit@email.xx>
285
286 The more complex forms are:
287
288 <proper@email.xx> <commit@email.xx>
289
290 which allows mailmap to replace only the email part of a commit, and:
291
292 Proper Name <proper@email.xx> <commit@email.xx>
293
294 which allows mailmap to replace both the name and the email of a commit
295 matching the specified commit email address, and:
296
297 Proper Name <proper@email.xx> Commit Name <commit@email.xx>
298
299 which allows mailmap to replace both the name and the email of a commit
300 matching both the specified commit name and email address.
301
302 Example 1: Your history contains commits by two authors, Jane and Joe,
303 whose names appear in the repository under several forms:
304
305 Joe Developer <joe@example.com>
306 Joe R. Developer <joe@example.com>
307 Jane Doe <jane@example.com>
308 Jane Doe <jane@laptop.(none)>
309 Jane D. <jane@desktop.(none)>
310
311
312 Now suppose that Joe wants his middle name initial used, and Jane
313 prefers her family name fully spelled out. A proper .mailmap file would
314 look like:
315
316 Jane Doe <jane@desktop.(none)>
317 Joe R. Developer <joe@example.com>
318
319
320 Note how there is no need for an entry for <jane@laptop[1].(none)>,
321 because the real name of that author is already correct.
322
323 Example 2: Your repository contains commits from the following authors:
324
325 nick1 <bugs@company.xx>
326 nick2 <bugs@company.xx>
327 nick2 <nick2@company.xx>
328 santa <me@company.xx>
329 claus <me@company.xx>
330 CTO <cto@coompany.xx>
331
332
333 Then you might want a .mailmap file that looks like:
334
335 <cto@company.xx> <cto@coompany.xx>
336 Some Dude <some@dude.xx> nick1 <bugs@company.xx>
337 Other Author <other@author.xx> nick2 <bugs@company.xx>
338 Other Author <other@author.xx> <nick2@company.xx>
339 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
340
341
342 Use hash # for comments that are either on their own line, or after the
343 email address.
344
346 git-annotate(1)
347
349 Written by Junio C Hamano <gitster@pobox.com[2]>
350
352 Part of the git(1) suite
353
355 1. jane@laptop
356 mailto:jane@laptop
357
358 2. gitster@pobox.com
359 mailto:gitster@pobox.com
360
361
362
363Git 1.7.1 08/16/2017 GIT-BLAME(1)