Git blame -C -C未生效?及文档术语含义技术咨询
git blame -C -C and Your Test Scenario Let’s tackle your two questions one by one, since the -C flags in git blame have some specific behavior that’s easy to misinterpret.
First: What exactly is "other files in the commit that created the target file"?
When you use git blame -C -C (or the shorthand -CC), this flag tells Git to look beyond the usual places (the current file’s history, and files modified in the same commit as the line you’re blaming) and add an extra check: all files that were modified or added in the exact commit where your target file was first created (i.e., the commit where git add <target-file> was first run).
Crucially, this is not all files in the entire repository at that commit’s tree — it’s only the files that were actually changed (added, modified, deleted) in that specific creation commit. Git doesn’t scan every file in the repo from that point in time; it only looks at the set of files that were part of the commit that brought your target file into existence.
Second: Why didn’t your test scenario detect the copied lines?
Let’s recap your test steps to diagnose this:
- Commit 1: Create non-empty
sourceand emptydest(both added in the same commit) - Commit 2: Add an unrelated file
- Commit 3: Copy some lines from
sourceintodest
When you ran git blame -CC dest, Git didn’t pick up the copy from source — here’s why:
- The
-CCflag only checks files in the commit wheredestwas created (Commit 1). In that commit,destis empty, and whilesourceexists there, those lines weren’t copied intodestuntil Commit 3. Git doesn’t retroactively link content fromsourcein Commit 1 todestin Commit 3 via-CCalone. -CCis limited to the creation commit’s changed files, but it doesn’t scan the entire repository’s history for matching content. To do that, you need the third level of-C:git blame -CCC dest(or-C -C -C).
The -CCC flag tells Git to scan every file in every commit in the entire repository to find the original source of the copied lines. In your test scenario, running this should correctly attribute the copied lines in dest back to their original location in source.
A quick side note: Git’s copy detection relies on matching contiguous lines (usually at least 3-4 lines by default, though this is configurable with --line-range). If you copied only 1-2 short, common lines, it might still miss them even with -CCC to avoid false positives.
内容的提问来源于stack exchange,提问作者user42768

