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] [-e] [-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/copying
124 within a file for it to associate those lines with the parent
125 commit. The default value is 20.
126
127 -C|<num>|
128 In addition to -M, detect lines moved or copied from other files
129 that were modified in the same commit. This is useful when you
130 reorganize your program and move code around across files. When
131 this option is given twice, the command additionally looks for
132 copies from other files in the commit that creates the file. When
133 this option is given three times, the command additionally looks
134 for copies from other files in any commit.
135
136 <num> is optional but it is the lower bound on the number of
137 alphanumeric characters that git must detect as moving/copying
138 between files for it to associate those lines with the parent
139 commit. And the default value is 40. If there are more than one -C
140 options given, the <num> argument of the last -C will take effect.
141
142 -h, --help
143 Show help message.
144
145 -c
146 Use the same output mode as git-annotate(1) (Default: off).
147
148 --score-debug
149 Include debugging information related to the movement of lines
150 between files (see -C) and lines moved within a file (see -M). The
151 first number listed is the score. This is the number of
152 alphanumeric characters detected as having been moved between or
153 within files. This must be above a certain threshold for git blame
154 to consider those lines of code to have been moved.
155
156 -f, --show-name
157 Show the filename in the original commit. By default the filename
158 is shown if there is any line that came from a file with a
159 different name, due to rename detection.
160
161 -n, --show-number
162 Show the line number in the original commit (Default: off).
163
164 -s
165 Suppress the author name and timestamp from the output.
166
167 -e, --show-email
168 Show the author email instead of author name (Default: off).
169
170 -w
171 Ignore whitespace when comparing the parent’s version and the
172 child’s to find where the lines came from.
173
175 In this format, each line is output after a header; the header at the
176 minimum has the first line which has:
177
178 · 40-byte SHA-1 of the commit the line is attributed to;
179
180 · the line number of the line in the original file;
181
182 · the line number of the line in the final file;
183
184 · on a line that starts a group of lines from a different commit than
185 the previous one, the number of lines in this group. On subsequent
186 lines this field is absent.
187
188 This header line is followed by the following information at least once
189 for each commit:
190
191 · the author name ("author"), email ("author-mail"), time
192 ("author-time"), and timezone ("author-tz"); similarly for
193 committer.
194
195 · the filename in the commit that the line is attributed to.
196
197 · the first line of the commit log message ("summary").
198
199 The contents of the actual line is output after the above header,
200 prefixed by a TAB. This is to allow adding more header elements later.
201
203 Unlike git blame and git annotate in older versions of git, the extent
204 of the annotation can be limited to both line ranges and revision
205 ranges. When you are interested in finding the origin for lines 40-60
206 for file foo, you can use the -L option like so (they mean the same
207 thing — both ask for 21 lines starting at line 40):
208
209 git blame -L 40,60 foo
210 git blame -L 40,+21 foo
211
212 Also you can use a regular expression to specify the line range:
213
214 git blame -L '/^sub hello {/,/^}$/' foo
215
216 which limits the annotation to the body of the hello subroutine.
217
218 When you are not interested in changes older than version v2.6.18, or
219 changes older than 3 weeks, you can use revision range specifiers
220 similar to git rev-list:
221
222 git blame v2.6.18.. -- foo
223 git blame --since=3.weeks -- foo
224
225 When revision range specifiers are used to limit the annotation, lines
226 that have not changed since the range boundary (either the commit
227 v2.6.18 or the most recent commit that is more than 3 weeks old in the
228 above example) are blamed for that range boundary commit.
229
230 A particularly useful way is to see if an added file has lines created
231 by copy-and-paste from existing files. Sometimes this indicates that
232 the developer was being sloppy and did not refactor the code properly.
233 You can first find the commit that introduced the file with:
234
235 git log --diff-filter=A --pretty=short -- foo
236
237 and then annotate the change between the commit and its parents, using
238 commit^! notation:
239
240 git blame -C -C -f $commit^! -- foo
241
243 When called with --incremental option, the command outputs the result
244 as it is built. The output generally will talk about lines touched by
245 more recent commits first (i.e. the lines will be annotated out of
246 order) and is meant to be used by interactive viewers.
247
248 The output format is similar to the Porcelain format, but it does not
249 contain the actual lines from the file that is being annotated.
250
251 1. Each blame entry always starts with a line of:
252
253 <40-byte hex sha1> <sourceline> <resultline> <num_lines>
254
255 Line numbers count from 1.
256
257 2. The first time that a commit shows up in the stream, it has various
258 other information about it printed out with a one-word tag at the
259 beginning of each line describing the extra commit information
260 (author, email, committer, dates, summary, etc.).
261
262 3. Unlike the Porcelain format, the filename information is always
263 given and terminates the entry:
264
265 "filename" <whitespace-quoted-filename-goes-here>
266
267 and thus it is really quite easy to parse for some line- and
268 word-oriented parser (which should be quite natural for most
269 scripting languages).
270
271 Note
272 For people who do parsing: to make it more robust, just ignore
273 any lines between the first and last one ("<sha1>" and
274 "filename" lines) where you do not recognize the tag words (or
275 care about that particular one) at the beginning of the
276 "extended information" lines. That way, if there is ever added
277 information (like the commit encoding or extended commit
278 commentary), a blame viewer will not care.
279
281 If the file .mailmap exists at the toplevel of the repository, or at
282 the location pointed to by the mailmap.file configuration option, it is
283 used to map author and committer names and email addresses to canonical
284 real names and email addresses.
285
286 In the simple form, each line in the file consists of the canonical
287 real name of an author, whitespace, and an email address used in the
288 commit (enclosed by < and >) to map to the name. For example:
289
290 Proper Name <commit@email.xx>
291
292 The more complex forms are:
293
294 <proper@email.xx> <commit@email.xx>
295
296 which allows mailmap to replace only the email part of a commit, and:
297
298 Proper Name <proper@email.xx> <commit@email.xx>
299
300 which allows mailmap to replace both the name and the email of a commit
301 matching the specified commit email address, and:
302
303 Proper Name <proper@email.xx> Commit Name <commit@email.xx>
304
305 which allows mailmap to replace both the name and the email of a commit
306 matching both the specified commit name and email address.
307
308 Example 1: Your history contains commits by two authors, Jane and Joe,
309 whose names appear in the repository under several forms:
310
311 Joe Developer <joe@example.com>
312 Joe R. Developer <joe@example.com>
313 Jane Doe <jane@example.com>
314 Jane Doe <jane@laptop.(none)>
315 Jane D. <jane@desktop.(none)>
316
317
318 Now suppose that Joe wants his middle name initial used, and Jane
319 prefers her family name fully spelled out. A proper .mailmap file would
320 look like:
321
322 Jane Doe <jane@desktop.(none)>
323 Joe R. Developer <joe@example.com>
324
325
326 Note how there is no need for an entry for <jane@laptop[1].(none)>,
327 because the real name of that author is already correct.
328
329 Example 2: Your repository contains commits from the following authors:
330
331 nick1 <bugs@company.xx>
332 nick2 <bugs@company.xx>
333 nick2 <nick2@company.xx>
334 santa <me@company.xx>
335 claus <me@company.xx>
336 CTO <cto@coompany.xx>
337
338
339 Then you might want a .mailmap file that looks like:
340
341 <cto@company.xx> <cto@coompany.xx>
342 Some Dude <some@dude.xx> nick1 <bugs@company.xx>
343 Other Author <other@author.xx> nick2 <bugs@company.xx>
344 Other Author <other@author.xx> <nick2@company.xx>
345 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
346
347
348 Use hash # for comments that are either on their own line, or after the
349 email address.
350
352 git-annotate(1)
353
355 Written by Junio C Hamano <gitster@pobox.com[2]>
356
358 Part of the git(1) suite
359
361 1. jane@laptop
362 mailto:jane@laptop
363
364 2. gitster@pobox.com
365 mailto:gitster@pobox.com
366
367
368
369Git 1.7.4.4 04/11/2011 GIT-BLAME(1)