Can we do better than "git checkout/add -p"
From: Junio C Hamano <hidden>
Date: 2026-08-07 04:02:45
I am doing more "git checkout -p" (selective revert of local changes out of the working tree files) these days, as well as "git add -p" (selective adding of local changes to the index), and what I often wish is to have _both_ as possible options in a single session. That is, the local changes in my working tree often fall into three categories. (1) One that is clearly good, (2) one that is good but not yet ready, and (3) one that is bogus and should be discarded. "git checkout -p" is a way that is very suitable for (3), while "git add -p" is a way to deal with (1). To (2), I say "no" in "git add -p", but there is no easy way from "git add -p" to say that the hunk is (3). My current workaround is not to use "git checkout -p" and instead (e)dit an undesirable hunk into a no-op hunk. This is serviceable, but with two caveats: - The underlying 'apply' machinery does not see a truly no-op, context-only hunk. You'd need to pretend removing an existing line and adding the same line back. - (e)dit applies the edited hunk right away without giving the user a chance to proofread and approve or reedit.