git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Can we do better than "git checkout/add -p"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 7, 2026, 04:02 UTC
Message-ID
<xmqq8q6ih924.fsf@gitster.g>

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.
Next: Christian Couder
Message 1 of 15 in “Can we do better than "git checkout/add -p"”
  1. Junio C HamanoAug 7, 2026
  2. Christian CouderAug 7, 2026
  3. D. Ben KnobleAug 7, 2026
  4. Junio C HamanoAug 7, 2026
  5. D. Ben KnobleAug 7, 2026
  6. Junio C HamanoAug 7, 2026
  7. Patrick SteinhardtAug 10, 2026
  8. Stefan HallerAug 10, 2026
  9. Patrick SteinhardtAug 10, 2026
  10. Junio C HamanoAug 10, 2026
  11. Patrick SteinhardtAug 11, 2026
  12. Johannes SchindelinAug 12, 2026
  13. Jeff KingAug 12, 2026
  14. Junio C HamanoAug 12, 2026
  15. Junio C HamanoAug 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.