The git blame
command annotates lines with information from the revision which last modified the line, and... with Git 2.22 (Q2 2019), will do so faster, because of a performance fix around "git blame
", especially in a linear history (which is the norm we should optimize for).
See commit f892014 (02 Apr 2019) by David Kastrup (fedelibre
).
(Merged by Junio C Hamano -- gitster
-- in commit 4d8c4da, 25 Apr 2019)
blame.c
: don't drop origin blobs as eagerly
When a parent blob already has chunks queued up for blaming, dropping the blob at the end of one blame step will cause it to get reloaded right away, doubling the amount of I/O and unpacking when processing a linear history.
Keeping such parent blobs in memory seems like a reasonable optimization that should incur additional memory pressure mostly when processing the merges from old branches.
Before Git 2.41 (Q2 2023), "git blame --contents=<file>
--
``"(man) used to be forbidden, but now it finds the origins of lines starting at <file>
contents through the history that leads to <rev>
.
See commit 1a3119e (24 Mar 2023) by Jacob Keller (jacob-keller
).
(Merged by Junio C Hamano -- gitster
-- in commit 62df03c, 04 Apr 2023)
blame
: allow --contents
to work with non-HEAD commit
Signed-off-by: Jacob Keller
The --contents
option can be used with git blame
(man) to blame the file as if it had the contents from the specified file.
This is akin to copying the contents into the working tree and then running git blame.
This option has been supported since 1cfe773 (git-blame
: no rev means start from the working tree file., 2007-01-30, Git v1.5.0-rc4 -- merge) ("git-blame
: no rev means start from the working tree file.")
The --contents
option always blames the file as if it was based on the current HEAD commit.
If you try to pass a revision while using --contents
, you get the following error:
fatal: cannot use --contents with final commit object name
This is because the blame process generates a fake working tree commit which always uses the HEAD object as its sole parent.
Enhance fake_working_tree_commit
to take the object ID to use for the parent instead of always using the HEAD object.
Then, always generate a fake commit when we have contents provided, even if we have a final object.
Remove the check to disallow --contents
and a final revision.
Note that the behavior of generating a fake working commit is still skipped when a revision is provided but --contents
is not provided.
Generating such a commit in that case would combine the currently checked out file contents with the provided revision, which breaks normal blame behavior and produces unexpected results.
This enables use of --contents
with an arbitrary revision, rather than forcing the use of the local HEAD commit.
This makes the --contents
option significantly more flexible, as it is no longer required to check out the working tree to the desired commit before using --contents.
blame-options
now includes in its man page:
Pretend the file being annotated has a commit with the
contents from the named file and a parent of <rev>
,
defaulting to HEAD when no <rev>
is specified.
You may
specify '-
' to make the command read from the standard
input for the file contents.
git blame
now includes in its man page:
[ --contents <file> ] [<rev> | --reverse <rev>..<rev>] [--] <file>
Still with Git 2.41 (Q2 2023), the output given by "git blame
"(man) that attributes a line to contents taken from the file specified by the --contents
option shows it differently from a line attributed to the working tree file.
See commit 603d0fd (24 Apr 2023) by Jacob Keller (jacob-keller
).
(Merged by Junio C Hamano -- gitster
-- in commit cf85f4b, 02 May 2023)
blame
: use different author name for fake commit generated by --contents
Suggested-by: Junio C Hamano
Suggested-by: Glen Choo
Signed-off-by: Jacob Keller
When the --contents
option is used with git blame
(man), and the contents of the file have lines which can't be annotated by the history being blamed, the user will see an author of "Not Committed Yet".
This is similar to the way blame handles working tree contents when blaming without a revision.
This is slightly confusing since this data isn't the working copy and while it is technically "not committed yet", its also coming from an external file.
Replace this author name with "External file (--contents)
" to better differentiate such lines from actual working copy lines.
blame-options
now includes in its man page:
Annotate using the contents from the named file, starting from <rev>
if it is specified, and HEAD otherwise.
You may specify '-' to make
the command read from the standard input for the file contents.