规划代码仓库历史重置
评估历史重置的替代方案,制定旧记录归档、新根提交、团队切换与一致性验证步骤。
完整提示词
<context>
Cutting history is a one-way door for everyone who has a clone. Every commit hash changes, so open pull requests, forks, tags, release notes, issue links to commits, deploy pins and `git blame` all stop matching. Done well, the new repository starts from one root commit of the current tree, and the old history lives in an archived repository or under a clearly named ref, so investigators can still reach it; `git replace --graft` can even stitch the old history back onto the new root in a local clone when someone needs blame across the cut. Two cases need extra care. If the reason is leaked secrets or personal data, a fresh start does not remove anything already cloned, forked or cached by the host: the secrets must be rotated, and the archived old history must be private and access-controlled, or deleted after a retention decision. If the reason is only size, a shallow or partial clone setup, or purging a few large files, may solve it with far less disruption, and should be checked first.
<reason>
{{reason}}
</reason>
{{#context}}
<context_given>
{{context}}
</context_given>
{{/context}}
</context>
<task>
1. Check the alternatives against the stated reason before cutting: partial or shallow clones and LFS for size, a targeted history purge for a few files, a new repository that keeps history for a fresh major version. If one of them fits, say so and stop unless the user still wants a fresh start.
2. Inspect read-only: size, branch and tag list, open pull requests, references to commit hashes in CI, deploys, submodules and docs.
3. Plan where the old history lives: an archived (read-only, private if sensitive) repository, or a namespaced ref such as `refs/archive/pre-reset`, with a tag at the last old commit. If the reason is secrets or personal data, list the rotations and the retention decision first.
4. Create the new history in a fresh clone, not the user's working copy: an orphan branch from the current tree, one root commit with a message naming the archive location and the last old commit hash, and recreated tags only for releases that should continue.
5. Show how to reconnect history locally with `git replace --graft <new-root> <old-tip>` for people who need blame across the cut, and that replace refs are not pushed by default.
6. Write the cutover runbook: freeze merges, land or close open pull requests, push the new main after confirmation, update protection rules, CI and deploy pins, and have every developer re-clone (or reset with care after saving local work). Include the announcement text.
7. Verify: the new tree matches the old tip exactly (`git diff <old-tip> <new-root>` is empty), the archive is reachable, CI passes on the new history.
</task>
<constraints>
- Never force-push, delete branches or delete the old repository without explicit confirmation; propose those steps as commands for the user to approve.
- Never present a fresh start as removing leaked secrets; rotation comes first.
- Work in a fresh clone so the user's local work is never touched.
</constraints>
<output_format>
## Is this the right tool
Alternatives checked and the verdict.
## Archive plan
Where the old history lives.
## New history
Commands, in order, marked where confirmation is needed.
## Reconnecting history
The graft method.
## Cutover runbook
Numbered steps and the announcement.
## Verification
Checks and results.
</output_format>可替换内容
- {{reason}}
- {{#context}}
- {{context}}
- {{/context}}
分类与标签
编程开发、仓库历史重置、版本控制、历史归档、团队迁移