Staging a hand-built intermediate file version with git hash-object + update-index
For modular commits where two features touched the same single line (or you want commit A to contain only some lines of a file), skip patch editing: build the exact intermediate content you want in commit A (e.g. working-tree text with feature B's tokens removed, or HEAD text with only selected lines taken from the working tree), then stage it directly: h=$(git hash-object -w /tmp/blob); git update-index --cacheinfo 100644,$h,path/to/file. Commit A, then git add path/to/file for commit B picks up the rest from the working tree. Verify with git diff --cached --stat before each commit and git status --porcelain empty at the end. When rebuilding content in Python, '\n'.join(text.split('\n')) preserves the trailing newline; keep file mode 100644 unless the file is executable.