After the AI Writes, Part 1: Don't Carry Someone Else's Work Into Your Commit
retained text
We share one checkout between several AI sessions. One git add -A put two other sessions' work in my commit. Body (1,893 characters incl. spaces, under Reddit's 4,000 limit; paste from the next line to the end, no Markdown needed): We run several AI coding sessions against the same working copy. Last month I added a section to a roadmap, checked git status, and committed. Later I found the commit also carried three cherry-pick markers from another session and two status lines from a third workstream. Nobody did anything exotic. A commit is made of the index, not of the files you edited. Four ways it happens, all observed: \- git add -A stages whole files by path, not your changes. Another session's uncommitted lines in the same file go in with yours. \- git commit with no pathspec commits the whole index, including work another session had already staged. \- git checkout REV -- FILE writes the index as well as the working tree. Restore the working tree afterwards and the next commit can publish the old version. \- Your untracked new file is not safe either: another session's git add -A picks it up. The third is the quiet one. The working tree looks right, the tests read the working tree, and the commit quietly reverts someone else's change. What we do now: 1) Commit with explicit paths: git commit -F msg.txt -- FILE1 FILE2. 2) Before a bare commit, run git diff --cached --name-only. One foreign file means stop. 3) For hot files that several sessions rewrite whole, back up, rebuild from HEAD, insert only your line, commit, then put the backup back. 4) Read old versions with git show SHA:PATH, never git checkout REV -- PATH. Two limits. A post-commit hook that amends without a pathspec defeats all of this. And if work was already swept in, rewriting history moves other people's commits, so record it instead. The full write-up, with the failure scenes and the exact checks: Curious whether other teams sharing a checkout with agents hit the same shape, and what they use to catch it.
document fetched 2026-11-12 00:23 · canonical https://reddit.com/r/ClaudeAI/comments/1xtdh8b/after_the_ai_writes_part_1_dont_carry_someone