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

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

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Aug 7, 2026, 11:24 UTC
Message-ID
<CALnO6CBu8ZBDk9YwLW2jVJtBUk1=pvai5QHiLN6XLOOL-3KA=g@mail.gmail.com>
In-Reply-To
<xmqq8q6ih924.fsf@gitster.g>
On Fri, Aug 7, 2026 at 12:03 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
>
> 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).

Not a core Git solution, but the interface provided by Fugitive [1] (inspired by Magit) makes it easy to browse all hunks, with options to (e.g.) stage, unstage, or revert.

(The revert command even shows how to bring back the reverted content, in case you made a mistake.)

It's a bit hard to explain how this works over email. There's an old video [2] which doesn't reflect many newer enhancements to Fugitive (e.g., you no longer need to open a file to diff it; you can toggle the "git diff" or "git diff --cached" view from within the status buffer---from there, all the staging/unstaging/discard maps work on individual hunks or ranges of lines), but still shows the general idea.

[1]: https://github.com/tpope/vim-fugitive [2]: http://vimcasts.org/episodes/fugitive-vim-working-with-the-git-index/

I raise this as the kind of interface we could learn from: emulating it might be a bit heavier (a full TUI?), but is certainly more convenient to use than the prompt-loop over hunks.

Best,
-- 
D. Ben Knoble
Previous: Christian CouderNext: Junio C Hamano
Message 3 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.