From 5ee220a11a139ef672e3825c8bbb2ef334a4ab19 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 27 Apr 2026 22:29:06 +0100 Subject: [PATCH] docs: add Never-rewrite-history guard to CLAUDE.md / AGENTS.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Append a `## Never rewrite history` section listing the destructive history operations that NEVER apply on a remote-tracked repo, with the canonical clean-working-tree sequence (`git fetch && reset --hard origin/main && clean -fd`) as the only correct alternative. Why: forensic sweep on 2026-04-27 found three workspace repos with no merge base at all with origin — independent `git init`/"fresh start" rewrites on different machines had produced identical content under entirely different SHAs, costing ~41 commits of redundant local work. This rule prevents that class of error structurally for both human and AI agents. Implements PyAutoLabs/PyAutoPrompt#7. Co-Authored-By: Claude Opus 4.7 (1M context) --- AGENTS.md | 23 +++++++++++++++++++++++ CLAUDE.md | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index e3019cd3e..78eed761a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -45,3 +45,26 @@ NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python -m pytest t 3. Run the full test suite: `python -m pytest test_autoarray/` 4. Ensure all tests pass before opening a PR. 5. If changing public API, note the change in your PR description — downstream packages (PyAutoGalaxy, PyAutoLens) and workspaces may need updates. +## Never rewrite history + +NEVER perform these operations on any repo with a remote: + +- `git init` in a directory already tracked by git +- `rm -rf .git && git init` +- Commit with subject "Initial commit", "Fresh start", "Start fresh", "Reset + for AI workflow", or any equivalent message on a branch with a remote +- `git push --force` to `main` (or any branch tracked as `origin/HEAD`) +- `git filter-repo` / `git filter-branch` on shared branches +- `git rebase -i` rewriting commits already pushed to a shared branch + +If the working tree needs a clean state, the **only** correct sequence is: + + git fetch origin + git reset --hard origin/main + git clean -fd + +This applies equally to humans, local Claude Code, cloud Claude agents, Codex, +and any other agent. The "Initial commit — fresh start for AI workflow" pattern +that appeared independently on origin and local for three workspace repos is +exactly what this rule prevents — it costs ~40 commits of redundant local work +every time it happens. diff --git a/CLAUDE.md b/CLAUDE.md index 495a13857..bade2d3e4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -179,3 +179,26 @@ This pattern is used in `autogalaxy/operate/lens_calc.py` for all `LensCalc` met ## Line Endings — Always Unix (LF) All files **must use Unix line endings (LF, `\n`)**. Never write `\r\n` line endings. +## Never rewrite history + +NEVER perform these operations on any repo with a remote: + +- `git init` in a directory already tracked by git +- `rm -rf .git && git init` +- Commit with subject "Initial commit", "Fresh start", "Start fresh", "Reset + for AI workflow", or any equivalent message on a branch with a remote +- `git push --force` to `main` (or any branch tracked as `origin/HEAD`) +- `git filter-repo` / `git filter-branch` on shared branches +- `git rebase -i` rewriting commits already pushed to a shared branch + +If the working tree needs a clean state, the **only** correct sequence is: + + git fetch origin + git reset --hard origin/main + git clean -fd + +This applies equally to humans, local Claude Code, cloud Claude agents, Codex, +and any other agent. The "Initial commit — fresh start for AI workflow" pattern +that appeared independently on origin and local for three workspace repos is +exactly what this rule prevents — it costs ~40 commits of redundant local work +every time it happens.