Git gives since option
git blame --since=3.weeks -- foo
Is there a way I can get the blame list between two date?
That is: something similar to git log --since
and --until
.
similar to git log since and until
That was discussed here in 2017.
First, git blame
takes options that are fed to git rev-list
, to limit the
commits being taken into account for blaming.
And git rev-list
does have:
-until=<date>
--before=<date>
Show commits older than a specific date.
So these options are not documented under git blame
, but git rev-list
.
BUT: said options are ignored by git blame
.
Ie, git blame --since=3.weeks --before=2.weeks -- foo
would not "error", but... would silently ignore the --before=2.weeks
part.
Junio C Hamano comments (speaking about commits, but that applies to dates too):
Many options that
rev-list
takes are parsed but then ignored byblame
, simply because they do not make much sense in the context of the command, and "--before
" is one of them.It is interesting to realize that "
--since
" (and its synonym "--after
") does make sense, unlike "--before
" (and its synonym "--until
") which does not.Let's imagine a history like this (time flows from left to right):
--c1--c2--c4--c6--c8--c9 \ / c3--c5--c7
where the tip of the history is at commit "
c9
", and the number in the name of each commit denotes its timestamp.
"
git rev-list c9
" starts from "c9
", and follows the chain of parents and would producec9
,c8
,c7
,c6
, ...,c1
, ....If you add "
--after 2
", i.e. "git rev-list --after 2 c9
" does exactly the same traversal as the above, but stops following the chain of parents for commits that is earlier than the specified time.If you add "
--before 6
", i.e. "git rev-list --before 6 c9
" does exactly the same traversal as the first one, but does not show the commit whose timestamp is later than the specified time.
It would be like saying "git rev-list c5 c6
" in the above topology; the traversal fromc9
down toc5
andc6
is done only to findc5
andc6
to start the "real" traversal from.Now, "
--after 2
" will still show "c9
", the tip you start your traversal from, and this is important in the context of "blame
".Unlike "
git rev-list
" (and "git log
" family of commands), which can take more than one positive endpoints in the history (e.g. it is perfectly sensible to ask "git log -p ^c1 c5 c6 -- myfile
" in the example topology above), "git blame
" must be given exactly one positive endpoint, as "git blame ^c1 c5 c6 -- myfile
" would not make any sense (ask: "do we want to know aboutmyfile
inc5
? ormyfile
inc6
?").