blob: ba5417567c4df286a95a99cf1ae3e02ee466458f [file] [log] [blame]
Junio C Hamanob33fb4f2006-04-18 21:30:511git-blame(1)
2============
3
4NAME
5----
Junio C Hamano6b2cee12006-08-26 08:43:316git-blame - Show what revision and author last modified each line of a file
Junio C Hamanob33fb4f2006-04-18 21:30:517
8SYNOPSIS
9--------
Junio C Hamanoe1aa7472006-11-09 07:37:5010[verse]
Junio C Hamano7e590a12013-06-02 23:46:5211'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]
Junio C Hamano8eac2682013-09-09 22:35:2012 [-L <range>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
Junio C Hamanoa7da1ba2016-01-13 00:19:4513 [--progress] [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>]
14 [--] <file>
Junio C Hamanob33fb4f2006-04-18 21:30:5115
16DESCRIPTION
17-----------
Junio C Hamano6b2cee12006-08-26 08:43:3118
19Annotates each line in the given file with information from the revision which
20last modified the line. Optionally, start annotating from the given revision.
21
Junio C Hamano8eac2682013-09-09 22:35:2022When specified one or more times, `-L` restricts annotation to the requested
23lines.
Junio C Hamanoe1aa7472006-11-09 07:37:5024
Junio C Hamano6a8a8482012-10-01 20:59:4125The origin of lines is automatically followed across whole-file
26renames (currently there is no option to turn the rename-following
27off). To follow lines moved from one file to another, or to follow
28lines that were copied and pasted from another file, etc., see the
29`-C` and `-M` options.
30
Junio C Hamanofd83b8e2009-03-22 08:21:4131The report does not tell you anything about lines which have been deleted or
Junio C Hamano1aa40d22010-01-21 17:46:4332replaced; you need to use a tool such as 'git diff' or the "pickaxe"
Junio C Hamano6b2cee12006-08-26 08:43:3133interface briefly mentioned in the following paragraph.
34
Junio C Hamano076ffcc2013-02-06 05:13:2135Apart from supporting file annotation, Git also supports searching the
Junio C Hamanof9771f62007-01-17 17:42:3036development history for when a code snippet occurred in a change. This makes it
Junio C Hamano6b2cee12006-08-26 08:43:3137possible to track when a code snippet was added to a file, moved or copied
38between files, and eventually deleted or replaced. It works by searching for
Junio C Hamano5b3533d2014-02-27 23:07:1539a text string in the diff. A small example of the pickaxe interface
40that searches for `blame_usage`:
Junio C Hamano6b2cee12006-08-26 08:43:3141
42-----------------------------------------------------------------------------
43$ git log --pretty=oneline -S'blame_usage'
445040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
45ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
46-----------------------------------------------------------------------------
Junio C Hamanob33fb4f2006-04-18 21:30:5147
48OPTIONS
49-------
Junio C Hamano0e3cb532007-04-17 08:28:1150include::blame-options.txt[]
51
52-c::
Junio C Hamano35738e82008-01-07 07:55:4653Use the same output mode as linkgit:git-annotate[1] (Default: off).
Junio C Hamanob33fb4f2006-04-18 21:30:5154
Junio C Hamano0e3cb532007-04-17 08:28:1155--score-debug::
56Include debugging information related to the movement of
57lines between files (see `-C`) and lines moved within a
58file (see `-M`). The first number listed is the score.
59This is the number of alphanumeric characters detected
Junio C Hamanofd83b8e2009-03-22 08:21:4160as having been moved between or within files. This must be above
Junio C Hamano1aa40d22010-01-21 17:46:4361a certain threshold for 'git blame' to consider those lines
Junio C Hamano0e3cb532007-04-17 08:28:1162of code to have been moved.
Junio C Hamanob33fb4f2006-04-18 21:30:5163
Junio C Hamanoeb415992008-06-08 22:49:4764-f::
65--show-name::
Junio C Hamanofd83b8e2009-03-22 08:21:4166Show the filename in the original commit. By default
67the filename is shown if there is any line that came from a
68file with a different name, due to rename detection.
Junio C Hamanoff4b4312006-10-25 22:55:3169
Junio C Hamanoeb415992008-06-08 22:49:4770-n::
71--show-number::
Junio C Hamanofd83b8e2009-03-22 08:21:4172Show the line number in the original commit (Default: off).
Junio C Hamanoff4b4312006-10-25 22:55:3173
Junio C Hamano469d60e2007-04-29 18:30:3474-s::
Junio C Hamanofd83b8e2009-03-22 08:21:4175Suppress the author name and timestamp from the output.
Junio C Hamano469d60e2007-04-29 18:30:3476
Junio C Hamanoed69a742010-12-01 03:09:2377-e::
78--show-email::
79Show the author email instead of author name (Default: off).
Junio C Hamanodf5384b2015-06-24 21:12:1280This can also be controlled via the `blame.showEmail` config
81option.
Junio C Hamanoed69a742010-12-01 03:09:2382
Junio C Hamano9e52d4e2007-06-13 08:29:3383-w::
Junio C Hamanofd83b8e2009-03-22 08:21:4184Ignore whitespace when comparing the parent's version and
85the child's to find where the lines came from.
Junio C Hamano9e52d4e2007-06-13 08:29:3386
Junio C Hamano209ebe82011-04-27 21:09:5987--abbrev=<n>::
88Instead of using the default 7+1 hexadecimal digits as the
89abbreviated object name, use <n>+1 digits. Note that 1 column
90is used for a caret to mark the boundary commit.
91
Junio C Hamano9e52d4e2007-06-13 08:29:3392
Junio C Hamanoff4b4312006-10-25 22:55:3193THE PORCELAIN FORMAT
94--------------------
95
96In this format, each line is output after a header; the
Junio C Hamanof9771f62007-01-17 17:42:3097header at the minimum has the first line which has:
Junio C Hamanoff4b4312006-10-25 22:55:3198
99- 40-byte SHA-1 of the commit the line is attributed to;
100- the line number of the line in the original file;
101- the line number of the line in the final file;
Junio C Hamanofd83b8e2009-03-22 08:21:41102- on a line that starts a group of lines from a different
Junio C Hamanoff4b4312006-10-25 22:55:31103 commit than the previous one, the number of lines in this
104 group. On subsequent lines this field is absent.
105
106This header line is followed by the following information
107at least once for each commit:
108
Junio C Hamanofd83b8e2009-03-22 08:21:41109- the author name ("author"), email ("author-mail"), time
Junio C Hamanoe3acfb82013-11-12 23:22:57110 ("author-time"), and time zone ("author-tz"); similarly
Junio C Hamanoff4b4312006-10-25 22:55:31111 for committer.
Junio C Hamanofd83b8e2009-03-22 08:21:41112- the filename in the commit that the line is attributed to.
Junio C Hamanoff4b4312006-10-25 22:55:31113- the first line of the commit log message ("summary").
114
115The contents of the actual line is output after the above
116header, prefixed by a TAB. This is to allow adding more
117header elements later.
118
Junio C Hamano2a294cd2011-05-23 23:06:31119The porcelain format generally suppresses commit information that has
120already been seen. For example, two lines that are blamed to the same
121commit will both be shown, but the details for that commit will be shown
122only once. This is more efficient, but may require more state be kept by
123the reader. The `--line-porcelain` option can be used to output full
124commit information for each line, allowing simpler (but less efficient)
125usage like:
126
127# count the number of lines attributed to each author
128git blame --line-porcelain file |
129sed -n 's/^author //p' |
130sort | uniq -c | sort -rn
131
Junio C Hamanoe1aa7472006-11-09 07:37:50132
Junio C Hamanof9771f62007-01-17 17:42:30133SPECIFYING RANGES
134-----------------
Junio C Hamanoe1aa7472006-11-09 07:37:50135
Junio C Hamano1aa40d22010-01-21 17:46:43136Unlike 'git blame' and 'git annotate' in older versions of git, the extent
Junio C Hamanofd83b8e2009-03-22 08:21:41137of the annotation can be limited to both line ranges and revision
Junio C Hamano8eac2682013-09-09 22:35:20138ranges. The `-L` option, which limits annotation to a range of lines, may be
139specified multiple times.
140
141When you are interested in finding the origin for
Junio C Hamanofd83b8e2009-03-22 08:21:41142lines 40-60 for file `foo`, you can use the `-L` option like so
Junio C Hamanoe58607f2007-01-17 23:27:45143(they mean the same thing -- both ask for 21 lines starting at
144line 40):
Junio C Hamanoe1aa7472006-11-09 07:37:50145
146git blame -L 40,60 foo
Junio C Hamanoe58607f2007-01-17 23:27:45147git blame -L 40,+21 foo
Junio C Hamanoe1aa7472006-11-09 07:37:50148
Junio C Hamanofd83b8e2009-03-22 08:21:41149Also you can use a regular expression to specify the line range:
Junio C Hamano4a345d22006-11-09 18:45:32150
151git blame -L '/^sub hello {/,/^}$/' foo
152
Junio C Hamanofd83b8e2009-03-22 08:21:41153which limits the annotation to the body of the `hello` subroutine.
Junio C Hamano4a345d22006-11-09 18:45:32154
Junio C Hamanofd83b8e2009-03-22 08:21:41155When you are not interested in changes older than version
Junio C Hamanoe1aa7472006-11-09 07:37:50156v2.6.18, or changes older than 3 weeks, you can use revision
Junio C Hamano1aa40d22010-01-21 17:46:43157range specifiers similar to 'git rev-list':
Junio C Hamanoe1aa7472006-11-09 07:37:50158
159git blame v2.6.18.. -- foo
160git blame --since=3.weeks -- foo
161
162When revision range specifiers are used to limit the annotation,
163lines that have not changed since the range boundary (either the
164commit v2.6.18 or the most recent commit that is more than 3
165weeks old in the above example) are blamed for that range
166boundary commit.
167
Junio C Hamanofd83b8e2009-03-22 08:21:41168A particularly useful way is to see if an added file has lines
Junio C Hamanoe1aa7472006-11-09 07:37:50169created by copy-and-paste from existing files. Sometimes this
170indicates that the developer was being sloppy and did not
171refactor the code properly. You can first find the commit that
172introduced the file with:
173
174git log --diff-filter=A --pretty=short -- foo
175
176and then annotate the change between the commit and its
Junio C Hamanob76a6862012-05-02 22:02:46177parents, using `commit^!` notation:
Junio C Hamanoe1aa7472006-11-09 07:37:50178
179git blame -C -C -f $commit^! -- foo
180
181
Junio C Hamano5a702332007-01-28 20:55:22182INCREMENTAL OUTPUT
183------------------
184
185When called with `--incremental` option, the command outputs the
186result as it is built. The output generally will talk about
187lines touched by more recent commits first (i.e. the lines will
188be annotated out of order) and is meant to be used by
189interactive viewers.
190
191The output format is similar to the Porcelain format, but it
192does not contain the actual lines from the file that is being
193annotated.
194
195. Each blame entry always starts with a line of:
196
197<40-byte hex sha1> <sourceline> <resultline> <num_lines>
198+
199Line numbers count from 1.
200
Junio C Hamanofd83b8e2009-03-22 08:21:41201. The first time that a commit shows up in the stream, it has various
Junio C Hamano5a702332007-01-28 20:55:22202 other information about it printed out with a one-word tag at the
Junio C Hamanofd83b8e2009-03-22 08:21:41203 beginning of each line describing the extra commit information (author,
204 email, committer, dates, summary, etc.).
Junio C Hamano5a702332007-01-28 20:55:22205
Junio C Hamanofd83b8e2009-03-22 08:21:41206. Unlike the Porcelain format, the filename information is always
Junio C Hamano5a702332007-01-28 20:55:22207 given and terminates the entry:
208
209"filename" <whitespace-quoted-filename-goes-here>
210+
Junio C Hamanofd83b8e2009-03-22 08:21:41211and thus it is really quite easy to parse for some line- and word-oriented
Junio C Hamano5a702332007-01-28 20:55:22212parser (which should be quite natural for most scripting languages).
213+
214[NOTE]
215For people who do parsing: to make it more robust, just ignore any
Junio C Hamanofd83b8e2009-03-22 08:21:41216lines between the first and last one ("<sha1>" and "filename" lines)
217where you do not recognize the tag words (or care about that particular
Junio C Hamano5a702332007-01-28 20:55:22218one) at the beginning of the "extended information" lines. That way, if
219there is ever added information (like the commit encoding or extended
Junio C Hamanofd83b8e2009-03-22 08:21:41220commit commentary), a blame viewer will not care.
Junio C Hamano5a702332007-01-28 20:55:22221
222
Junio C Hamano8bc410e2009-02-15 10:38:19223MAPPING AUTHORS
224---------------
225
226include::mailmap.txt[]
227
228
Junio C Hamanob33fb4f2006-04-18 21:30:51229SEE ALSO
230--------
Junio C Hamano35738e82008-01-07 07:55:46231linkgit:git-annotate[1]
Junio C Hamanob33fb4f2006-04-18 21:30:51232
Junio C Hamanob33fb4f2006-04-18 21:30:51233GIT
234---
Junio C Hamanof7c042d2008-06-06 22:50:53235Part of the linkgit:git[1] suite