aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/blame-options.txt
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2023-03-24 10:08:00 -0700
committerJunio C Hamano <gitster@pobox.com>2023-03-24 12:05:22 -0700
commit1a3119ed06c8fbb1c00a6aa3615299252575abab (patch)
tree681dc2f032eb3f96458a56fb83078cce761b626d /Documentation/blame-options.txt
parent73876f4861cd3d187a4682290ab75c9dccadbc56 (diff)
downloadgit-1a3119ed06c8fbb1c00a6aa3615299252575abab.tar.gz
blame: allow --contents to work with non-HEAD commit
The --contents option can be used with git blame 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 1cfe77333f27 ("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. Reword the documentation so that its clear that --contents can be used with <rev>. Add tests for the --contents option to the annotate-tests.sh test script. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation/blame-options.txt')
-rw-r--r--Documentation/blame-options.txt10
1 files changed, 5 insertions, 5 deletions
diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index 9a663535f4..95599bd6e5 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -64,11 +64,11 @@ include::line-range-format.txt[]
manual page.
--contents <file>::
- When <rev> is not specified, the command annotates the
- changes starting backwards from the working tree copy.
- This flag makes the command pretend as if the working
- tree copy has the contents of the named file (specify
- `-` to make the command read from the standard input).
+ 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.
--date <format>::
Specifies the format used to output dates. If --date is not