Skip to content

Commit ac3a444

Browse files
danielkoninggitster
authored andcommitted
blame: document actual range specifier behavior
The git-blame(1) man page says that the .. range specifier can be used to exclude changes "older than" a certain revision. It goes on to say that it collapses all lines "not changed since the range boundary" into the boundary revision. This is the same thing --since=<rev-date> would do, and the man page even uses .. and --since in parallel as if to imply that they're alternative means of achieving the same output. In fact, this isn't true! On the git-rev-list(1) and gitrevisions(7) man pages, it's explained that the .. specifier excludes all ancestors of the commit, not all commits on an earlier date. 'blame' is not an exception to this behavior; it uses the same functions as other commands to parse a specifier and build a revision set. If you execute: ---- #!/bin/sh mkdir blame-test pushd blame-test git init echo "line added at root" > foo echo "another line added at root" >> foo git add foo git commit -am "#1 chronologically" git checkout -b side sed '2i\ line added only on side branch ' foo > bar mv bar foo git commit -am "#2 chronologically" git checkout master echo "line added only on master branch" >> foo git commit -am "#3 chronologically" git tag boundary git merge side -m "#4 chronologically" git blame boundary.. foo popd blame-test ---- then you'll see that 'blame' treats the range specifier as 'rev-list' would: the second line is attributed to a commit which occured chronologically before `boundary`. (I guess a case could be made for an off-kilter interpretation of the phrasing, under which "since the range boundary" includes any commits not yet known to that boundary. But that would contradict the use of "since" as the name of the other limiting option, which *does* perform an absolute time cutoff.) There is at least one porcelain in fairly wide use which takes this passage of the manual at its word, so I'm not the only one who finds it confusing. I think the phrasing in the following patch is both clearer and more accurate. Signed-off-by: Daniel Koning <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c20df8 commit ac3a444

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

Documentation/git-blame.txt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,26 @@ Also you can use a regular expression to specify the line range:
153153

154154
which limits the annotation to the body of the `hello` subroutine.
155155

156-
When you are not interested in changes older than version
157-
v2.6.18, or changes older than 3 weeks, you can use revision
158-
range specifiers similar to 'git rev-list':
159-
160-
git blame v2.6.18.. -- foo
161-
git blame --since=3.weeks -- foo
162-
163-
When revision range specifiers are used to limit the annotation,
164-
lines that have not changed since the range boundary (either the
165-
commit v2.6.18 or the most recent commit that is more than 3
166-
weeks old in the above example) are blamed for that range
167-
boundary commit.
156+
When you are only interested in recent changes, you can use revision
157+
range specifiers and limiting options, just as with 'git rev-list'.
158+
159+
You can limit the annotation to commits from the past 3 weeks:
160+
161+
git blame --since=3.weeks -- foo
162+
163+
The oldest commit in that span of time will be given the blame for any
164+
lines that have not changed since.
165+
166+
Or you can limit the annotation to commits that are not ancestors of
167+
v2.6.18:
168+
169+
git blame v2.6.18.. -- foo
170+
171+
Unlike the --since option, the two-dot range specifier does not perform
172+
a date-based cutoff. If changes from branch `fix` were merged in after
173+
v2.6.18, the commits on `fix` which introduced those changes will appear
174+
in the output of 'git blame', even if those commits took place at an
175+
earlier time than v2.6.18.
168176

169177
A particularly useful way is to see if an added file has lines
170178
created by copy-and-paste from existing files. Sometimes this

0 commit comments

Comments
 (0)