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

"D. Ben Knoble" <[email protected]>
Newsgroups org.kernel.vger.git
Message-ID <CALnO6CBu8ZBDk9YwLW2jVJtBUk1=pvai5QHiLN6XLOOL-3KA=g@mail.gmail.com>
On Fri, Aug 7, 2026 at 12:03 AM Junio C Hamano <[email protected]> wrote:
>
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.