blob: ff54d29d70311643a9e9f03b2e384d7fa0a5baa0 [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]
11'git-blame' [-c] [-l] [-t] [-f] [-n] [-p] [-L n,m] [-S <revs-file>]
12 [-M] [-C] [-C] [--since=<date>] [<rev>] [--] <file>
Junio C Hamanob33fb4f2006-04-18 21:30:5113
14DESCRIPTION
15-----------
Junio C Hamano6b2cee12006-08-26 08:43:3116
17Annotates each line in the given file with information from the revision which
18last modified the line. Optionally, start annotating from the given revision.
19
Junio C Hamanoe1aa7472006-11-09 07:37:5020Also it can limit the range of lines annotated.
21
Junio C Hamano6b2cee12006-08-26 08:43:3122This report doesn't tell you anything about lines which have been deleted or
23replaced; you need to use a tool such as gitlink:git-diff[1] or the "pickaxe"
24interface briefly mentioned in the following paragraph.
25
26Apart from supporting file annotation, git also supports searching the
27development history for when a code snippet occured in a change. This makes it
28possible to track when a code snippet was added to a file, moved or copied
29between files, and eventually deleted or replaced. It works by searching for
30a text string in the diff. A small example:
31
32-----------------------------------------------------------------------------
33$ git log --pretty=oneline -S'blame_usage'
345040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
35ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
36-----------------------------------------------------------------------------
Junio C Hamanob33fb4f2006-04-18 21:30:5137
38OPTIONS
39-------
Junio C Hamano341071d2006-06-04 07:24:4840-c, --compatibility::
Junio C Hamano6b2cee12006-08-26 08:43:3141Use the same output mode as gitlink:git-annotate[1] (Default: off).
Junio C Hamanob33fb4f2006-04-18 21:30:5142
Junio C Hamanoe1aa7472006-11-09 07:37:5043-L n,m::
44Annotate only the specified line range (lines count from
451). The range can be specified with a regexp. For
46example, `-L '/^sub esc_html /,/^}$/'` limits the
47annotation only to the body of `esc_html` subroutine.
48
Junio C Hamanob33fb4f2006-04-18 21:30:5149-l, --long::
Junio C Hamano3fd90c82006-06-18 00:22:0150Show long rev (Default: off).
51
52-t, --time::
53Show raw timestamp (Default: off).
Junio C Hamanob33fb4f2006-04-18 21:30:5154
55-S, --rev-file <revs-file>::
Junio C Hamano6b2cee12006-08-26 08:43:3156Use revs from revs-file instead of calling gitlink:git-rev-list[1].
Junio C Hamanob33fb4f2006-04-18 21:30:5157
Junio C Hamanoff4b4312006-10-25 22:55:3158-f, --show-name::
59Show filename in the original commit. By default
60filename is shown if there is any line that came from a
61file with different name, due to rename detection.
62
63-n, --show-number::
64Show line number in the original commit (Default: off).
65
66-p, --porcelain::
67Show in a format designed for machine consumption.
68
Junio C Hamanoe1aa7472006-11-09 07:37:5069-M::
70Detect moving lines in the file as well. When a commit
71moves a block of lines in a file (e.g. the original file
72has A and then B, and the commit changes it to B and
73then A), traditional 'blame' algorithm typically blames
74the lines that were moved up (i.e. B) to the parent and
75assigns blame to the lines that were moved down (i.e. A)
76to the child commit. With this option, both groups of
77lines are blamed on the parent.
78
79-C::
80In addition to `-M`, detect lines copied from other
81files that were modified in the same commit. This is
82useful when you reorganize your program and move code
83around across files. When this option is given twice,
84the command looks for copies from all other files in the
85parent for the commit that creates the file in addition.
86
Junio C Hamanob33fb4f2006-04-18 21:30:5187-h, --help::
88Show help message.
89
90
Junio C Hamanoff4b4312006-10-25 22:55:3191THE PORCELAIN FORMAT
92--------------------
93
94In this format, each line is output after a header; the
95header at the minumum has the first line which has:
96
97- 40-byte SHA-1 of the commit the line is attributed to;
98- the line number of the line in the original file;
99- the line number of the line in the final file;
100- on a line that starts a group of line from a different
101 commit than the previous one, the number of lines in this
102 group. On subsequent lines this field is absent.
103
104This header line is followed by the following information
105at least once for each commit:
106
107- author name ("author"), email ("author-mail"), time
108 ("author-time"), and timezone ("author-tz"); similarly
109 for committer.
110- filename in the commit the line is attributed to.
111- the first line of the commit log message ("summary").
112
113The contents of the actual line is output after the above
114header, prefixed by a TAB. This is to allow adding more
115header elements later.
116
Junio C Hamanoe1aa7472006-11-09 07:37:50117
118SPECIFIYING RANGES
119------------------
120
121Unlike `git-blame` and `git-annotate` in older git, the extent
122of annotation can be limited to both line ranges and revision
123ranges. When you are interested in finding the origin for
124ll. 40-60 for file `foo`, you can use `-L` option like this:
125
126git blame -L 40,60 foo
127
128When you are not interested in changes older than the version
129v2.6.18, or changes older than 3 weeks, you can use revision
130range specifiers similar to `git-rev-list`:
131
132git blame v2.6.18.. -- foo
133git blame --since=3.weeks -- foo
134
135When revision range specifiers are used to limit the annotation,
136lines that have not changed since the range boundary (either the
137commit v2.6.18 or the most recent commit that is more than 3
138weeks old in the above example) are blamed for that range
139boundary commit.
140
141A particularly useful way is to see if an added file have lines
142created by copy-and-paste from existing files. Sometimes this
143indicates that the developer was being sloppy and did not
144refactor the code properly. You can first find the commit that
145introduced the file with:
146
147git log --diff-filter=A --pretty=short -- foo
148
149and then annotate the change between the commit and its
150parents, using `commit{caret}!` notation:
151
152git blame -C -C -f $commit^! -- foo
153
154
Junio C Hamanob33fb4f2006-04-18 21:30:51155SEE ALSO
156--------
157gitlink:git-annotate[1]
158
159AUTHOR
160------
Junio C Hamanoe1aa7472006-11-09 07:37:50161Written by Junio C Hamano <junkio@cox.net>
Junio C Hamanob33fb4f2006-04-18 21:30:51162
163GIT
164---
165Part of the gitlink:git[7] suite