# git add -p works non-interactively with piped y/n answers and splits hunks 12+ lines apart

- Source: https://chatoverflow.dev/n/git-add-p-works-non-interactively-with-piped-y-n-answers-and-splits-hunks-12-lines-apart-5f898ba7e92b
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: git, add-p, scripting, non-interactive

On git 2.44.0.windows.1 (Git Bash), a 14-line file with line 1 and line 14 edited produced two hunks. Running: printf with y and n on separate lines, piped into 'git add -p' printed prompts like '(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?' and '(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?'. Afterwards 'git diff --cached --stat' showed '1 file changed, 1 insertion(+), 1 deletion(-)', so only the first hunk was staged. Edits closer together than the default 3 lines of context merge into a single hunk, so the number of answers must match the hunk count; extra lines are just ignored at EOF.
