返回提示词目录第 1308 页

追溯代码变更原因与历史

通过提交、评审与议题记录还原代码演变,输出变更时间线、证据和可咨询的相关人员。

完整提示词

<context>
`git blame` alone usually points at the wrong commit: a reformat, a file move or a mass rename. The decision you care about is often several commits back, and the reason lives in a commit body, a pull request description, a linked issue or a code review thread. Good code archaeology follows the code through moves, finds the commit that introduced or changed the specific behaviour, reads the surrounding discussion, and separates what the record says from what is inferred.
</context>

<task>
Answer this question about {{file_or_symbol}}: {{question}}

Access mode: {{repo_access}}. In `local` mode, run read-only git commands yourself. In `pasted-log` mode, work only from what the user pasted; if it is not enough, list the exact commands for the user to run and stop.

1. Locate the code today and confirm it exists as described. If it does not, search for it (`git grep`, `git log -S`) and report where it went.
2. Find the change that matters, skipping noise:
   - `git blame -w -C -C -M` on the relevant lines, honouring `.git-blame-ignore-revs` if present (`--ignore-revs-file`), to see past whitespace changes, moves and copies.
   - The pickaxe: `git log -S'<literal>'` for when a string or value appeared or disappeared, and `git log -G'<regex>'` for changes to lines matching a pattern.
   - Line history: `git log -L <start>,<end>:<file>` or `git log -L :<function>:<file>` to see every version of the function.
   - `git log --follow -p -- <file>` across renames.
   - For a change that looks reverted or reintroduced, check for revert commits and cherry-picks.
3. For each relevant commit, read the full message (`git show --stat <sha>`), and look for a pull request or merge request number, an issue or ticket id, a linked design document, or a co-author. If the hosting CLI is available and authenticated, read the pull request description and review comments; otherwise give the link pattern for the user to open.
4. Reconstruct the decision: what the code did before, what changed, who changed it and when, the stated reason, and any later change that modified the original intent.
5. Name who to ask: the authors and reviewers of the key commits who are still active in recent history (`git shortlog -sne --since=<date> -- <path>`), and the current owners if a CODEOWNERS file exists. Use names or handles as they appear in the repository; do not look people up elsewhere.
6. Before answering, check each claim against a commit, diff or pull request you actually read, and label everything else as inference.
</task>

<constraints>
- Read-only: never commit, check out, reset, rebase, stash or modify the working tree or any branch. Do not fetch or push unless the user asks.
- Quote commit messages and pull request text exactly when they are evidence; do not paraphrase them into stronger claims.
- If the record does not explain why, say "the history does not record a reason" instead of inventing one.
- Do not include email addresses in the report; use names or handles.
{{> guardrails/scope-discipline}}
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Answer
Two to four sentences that answer {{question}} directly, with the key commit.

## Timeline
| Date | Commit | Author | Change | Stated reason |

## Evidence
Quoted commit messages, pull request or issue excerpts, and short diffs that support the answer.

## Confidence
High, medium or low, and what would raise it. List every inference explicitly.

## Who to ask
Names or handles, their role in the change, and whether they are still active in this area.

## Commands used
The git commands you ran, or the ones the user should run in pasted-log mode.
</output_format>

可替换内容

  • {{file_or_symbol}}
  • {{question}}
  • {{repo_access}}
  • {{> guardrails/scope-discipline}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、代码考古、提交历史、变更溯源、评审记录

前往 AI 图片创作