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

DESCRIPTION

15       Annotates each line in the given file with information from the
16       revision which last modified the line. Optionally, start annotating
17       from the given revision.
18
19       Also it can limit the range of lines annotated.
20
21       This report doesn´t tell you anything about lines which have been
22       deleted or replaced; you need to use a tool such as git-diff(1) or the
23       "pickaxe" interface briefly mentioned in the following paragraph.
24
25       Apart from supporting file annotation, git also supports searching the
26       development history for when a code snippet occurred in a change. This
27       makes it possible to track when a code snippet was added to a file,
28       moved or copied between files, and eventually deleted or replaced. It
29       works by searching for a text string in the diff. A small example:
30
31
32
33           $ git log --pretty=oneline -S´blame_usage´
34           5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
35           ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
36
37

OPTIONS

39       -b
40           Show blank SHA-1 for boundary commits. This can also be controlled
41           via the blame.blankboundary config option.
42
43       --root
44           Do not treat root commits as boundaries. This can also be
45           controlled via the blame.showroot config option.
46
47       --show-stats
48           Include additional statistics at the end of blame output.
49
50       -L <start>,<end>
51           Annotate only the given line range. <start> and <end> can take one
52           of these forms:
53
54
55           ·   number
56
57               If <start> or <end> is a number, it specifies an absolute line
58               number (lines count from 1).
59
60           ·   /regex/
61
62               This form will use the first line matching the given POSIX
63               regex. If <end> is a regex, it will search starting at the line
64               given by <start>.
65
66           ·   +offset or -offset
67
68               This is only valid for <end> and will specify a number of lines
69               before or after the line given by <start>.
70
71       -l
72           Show long rev (Default: off).
73
74       -t
75           Show raw timestamp (Default: off).
76
77       -S <revs-file>
78           Use revs from revs-file instead of calling git-rev-list(1).
79
80       -p, --porcelain
81           Show in a format designed for machine consumption.
82
83       --incremental
84           Show the result incrementally in a format designed for machine
85           consumption.
86
87       --contents <file>
88           When <rev> is not specified, the command annotates the changes
89           starting backwards from the working tree copy. This flag makes the
90           command pretend as if the working tree copy has the contents of he
91           named file (specify - to make the command read from the standard
92           input).
93
94       -M|<num>|
95           Detect moving lines in the file as well. When a commit moves a
96           block of lines in a file (e.g. the original file has A and then B,
97           and the commit changes it to B and then A), traditional blame
98           algorithm typically blames the lines that were moved up (i.e. B) to
99           the parent and assigns blame to the lines that were moved down
100           (i.e. A) to the child commit. With this option, both groups of
101           lines are blamed on the parent.
102
103           <num> is optional but it is the lower bound on the number of
104           alphanumeric characters that git must detect as moving within a
105           file for it to associate those lines with the parent commit.
106
107       -C|<num>|
108           In addition to -M, detect lines copied from other files that were
109           modified in the same commit. This is useful when you reorganize
110           your program and move code around across files. When this option is
111           given twice, the command looks for copies from all other files in
112           the parent for the commit that creates the file in addition.
113
114           <num> is optional but it is the lower bound on the number of
115           alphanumeric characters that git must detect as moving between
116           files for it to associate those lines with the parent commit.
117
118       -h, --help
119           Show help message.
120
121       -c
122           Use the same output mode as git-annotate(1) (Default: off).
123
124       --score-debug
125           Include debugging information related to the movement of lines
126           between files (see -C) and lines moved within a file (see -M). The
127           first number listed is the score. This is the number of
128           alphanumeric characters detected to be moved between or within
129           files. This must be above a certain threshold for git-blame to
130           consider those lines of code to have been moved.
131
132       -f, --show-name
133           Show filename in the original commit. By default filename is shown
134           if there is any line that came from a file with different name, due
135           to rename detection.
136
137       -n, --show-number
138           Show line number in the original commit (Default: off).
139
140       -s
141           Suppress author name and timestamp from the output.
142
143       -w
144           Ignore whitespace when comparing parent´s version and child´s to
145           find where the lines came from.
146

THE PORCELAIN FORMAT

148       In this format, each line is output after a header; the header at the
149       minimum has the first line which has:
150
151
152       ·   40-byte SHA-1 of the commit the line is attributed to;
153
154       ·   the line number of the line in the original file;
155
156       ·   the line number of the line in the final file;
157
158       ·   on a line that starts a group of line from a different commit than
159           the previous one, the number of lines in this group. On subsequent
160           lines this field is absent.
161       This header line is followed by the following information at least once
162       for each commit:
163
164
165       ·   author name ("author"), email ("author-mail"), time
166           ("author-time"), and timezone ("author-tz"); similarly for
167           committer.
168
169       ·   filename in the commit the line is attributed to.
170
171       ·   the first line of the commit log message ("summary").
172       The contents of the actual line is output after the above header,
173       prefixed by a TAB. This is to allow adding more header elements later.
174

SPECIFYING RANGES

176       Unlike git-blame and git-annotate in older git, the extent of
177       annotation can be limited to both line ranges and revision ranges. When
178       you are interested in finding the origin for ll. 40-60 for file foo,
179       you can use -L option like these (they mean the same thing — both ask
180       for 21 lines starting at line 40):
181
182
183           git blame -L 40,60 foo
184           git blame -L 40,+21 foo
185       Also you can use regular expression to specify the line range.
186
187
188           git blame -L ´/^sub hello {/,/^}$/´ foo
189       would limit the annotation to the body of hello subroutine.
190
191       When you are not interested in changes older than the version v2.6.18,
192       or changes older than 3 weeks, you can use revision range specifiers
193       similar to git-rev-list:
194
195
196           git blame v2.6.18.. -- foo
197           git blame --since=3.weeks -- foo
198       When revision range specifiers are used to limit the annotation, lines
199       that have not changed since the range boundary (either the commit
200       v2.6.18 or the most recent commit that is more than 3 weeks old in the
201       above example) are blamed for that range boundary commit.
202
203       A particularly useful way is to see if an added file have lines created
204       by copy-and-paste from existing files. Sometimes this indicates that
205       the developer was being sloppy and did not refactor the code properly.
206       You can first find the commit that introduced the file with:
207
208
209           git log --diff-filter=A --pretty=short -- foo
210       and then annotate the change between the commit and its parents, using
211       commit^! notation:
212
213
214           git blame -C -C -f $commit^! -- foo
215

INCREMENTAL OUTPUT

217       When called with --incremental option, the command outputs the result
218       as it is built. The output generally will talk about lines touched by
219       more recent commits first (i.e. the lines will be annotated out of
220       order) and is meant to be used by interactive viewers.
221
222       The output format is similar to the Porcelain format, but it does not
223       contain the actual lines from the file that is being annotated.
224
225
226        1.  Each blame entry always starts with a line of:
227
228
229               <40-byte hex sha1> <sourceline> <resultline> <num_lines>
230           Line numbers count from 1.
231
232        2.  The first time that commit shows up in the stream, it has various
233           other information about it printed out with a one-word tag at the
234           beginning of each line about that "extended commit info" (author,
235           email, committer, dates, summary etc).
236
237        3.  Unlike Porcelain format, the filename information is always given
238           and terminates the entry:
239
240
241               "filename" <whitespace-quoted-filename-goes-here>
242           and thus it´s really quite easy to parse for some line- and
243           word-oriented parser (which should be quite natural for most
244           scripting languages).
245
246           Note
247           For people who do parsing: to make it more robust, just ignore any
248           lines in between the first and last one ("<sha1>" and "filename"
249           lines) where you don´t recognize the tag-words (or care about that
250           particular one) at the beginning of the "extended information"
251           lines. That way, if there is ever added information (like the
252           commit encoding or extended commit commentary), a blame viewer
253           won´t ever care.
254
255

SEE ALSO

257       git-annotate(1)
258

AUTHOR

260       Written by Junio C Hamano <junkio@cox.net>
261

GIT

263       Part of the git(7) suite
264
265
266
267
268Git 1.5.3.3                       10/09/2007                      GIT-BLAME(1)
Impressum