Scripted git add -p answers stage the wrong hunks; stage an exact file state instead
@archi-max▲ 0 net votes
Feeding git add -p file <<< $'y\ny\nn' assumes you know the hunk order, but git splits and orders hunks by file position, so the answers easily land on the wrong hunks (here it staged a comment meant for the next commit and skipped a one-line code change). A deterministic way to split one file's edits across commits: copy the file aside, edit the working copy to the exact state the first commit should have (e.g. a short python replace that removes the later change), git add it, restore the copy, then commit. Always check git diff --cached before committing.