← ClaudeAtlas

git-add-u-after-async-post-commit-hooklisted

Prevent (and recover from) `git add -u` + `git commit --amend` + `git push --force-with-lease` catastrophically rolling thousands of unrelated tracked-file deletions into an amended commit when the project has an async post-commit hook that mutates tracked files (e.g. regenerates `docs/site/*.html`, `docs/site/index.html`, `MEMORY.md`, or any other tracked artefact in a background `&` / `nohup` / "running … in background" process). Use when: (1) you just made a small commit, the post-commit log line says `[post-commit] … running … in background`, and you're about to amend with corrected message / typo / issue ref; (2) `git commit --amend` output reports `1000+ files changed, … insertions, NNN,NNN deletions(-)` when you only intended a 6-file change; (3) the force-pushed branch on origin shows a massive deletion diff and `git status` after the amend shows previously-tracked files like `MEMORY.md`, `.github/`, `.cursor/`, `scripts/` as Untracked; (4) you ran `git add -u` reflexively before `--amend` on a projec
wan-huiyan/agent-traffic-control · ★ 2 · Code & Development · score 79
Install: claude install-skill wan-huiyan/agent-traffic-control
# `git add -u` after async post-commit hook stages tracked-file deletions ## Problem You make a clean commit. The project's post-commit hook prints something like: ``` [post-commit] Python files changed — running doc update in background... ``` You then need to amend the commit (typo in message, wrong issue reference, etc.). You reach for the muscle-memory sequence: ```sh git add -u && git commit --amend -m "..." # ← TRAP ``` The amend output reports something terrifying: ``` [your-branch 480e2226] fix(...): your message 1493 files changed, 4 insertions(+), 368977 deletions(-) delete mode 100644 .claude-memory/MEMORY.md delete mode 100644 .claude-memory/SESSION_CHECKPOINT_*.md delete mode 100644 scripts/... ... ``` If you immediately ran `git push --force-with-lease`, that catastrophe is now on the remote branch. The remote PR diff shows thousands of unrelated deletions mixed with your intended 6-file fix. `git status` afterwards reveals the smoking gun — files that WERE tracked before the amend now show as **Untracked**: ``` On branch your-branch Your branch is up to date with 'origin/your-branch'. Untracked files: .claude-memory/ .cursor/ .github/ MEMORY.md PRODUCT.md scripts/ ``` ## Why it happens The async post-commit hook fires after your *first* commit and starts a background process that: 1. Reads tracked files (e.g. `MEMORY.md`, `docs/site/*.html`). 2. Regenerates / renames / moves / deletes them as