threads / discuss / 50243

Stage or discard a hunk at a time?

Subject: Stage or discard a hunk at a time?

## tl;dr

4 messages between Jan 16, 2019 and Apr 30, 2019.

replies: 3people: 4as markdown or json

Cameron Steffen· Jan 16, 2019, 19:09 UTC · lore
Hello,

I have this feature idea for git. There should be a command that effectively combines git add -p and git checkout -p so that I can navigate changed hunks and either stage or discard them.

There is already a SO question asking about this exactly... https://stackoverflow.com/questions/11538650/simultaneously-git-add-p-and-git-checkout-p

Has this been discussed before? Is this a reasonable request? If so, I might look into contributing the change myself.

Cameron
Jeff King· Apr 22, 2019, 19:28 UTC · re: Cameron Steffen · lore

Re: Stage or discard a hunk at a time?

On Wed, Jan 16, 2019 at 01:09:03PM -0600, Cameron Steffen wrote:
Show 9 quoted lines
> I have this feature idea for git. There should be a command that
> effectively combines git add -p and git checkout -p so that I can
> navigate changed hunks and either stage or discard them.
> 
> There is already a SO question asking about this exactly...
> https://stackoverflow.com/questions/11538650/simultaneously-git-add-p-and-git-checkout-p
> 
> Has this been discussed before? Is this a reasonable request? If so, I
> might look into contributing the change myself.

This is something I've sometimes wanted, too. I don't think it would be _too_ hard to do by modifying the add-interactive code. Both of those operations are driven by the same code; see the %patch_modes hash in git-add--interactive.perl, which defines the various situations. You would need to modify the actual code to handle the tri-state (there is not just "yes, apply it" and "no, leave it alone", but now "apply / discard / skip"). But it seems do-able.

If you do plan to work on it, be aware that the perl bits of add--interactive are being re-written in C. So it might make sense to target the new C implementation instead of modifying the perl.

-Peff
PS Sorry for the slow reply, and I hope you're still interested in the
   topic. Your message got throw onto my "interesting, should reply"
   pile and I just happened to see it while clearing out old mails. :)
Johannes Schindelin· Apr 30, 2019, 23:19 UTC · re: Jeff King · lore

Re: Stage or discard a hunk at a time?

Hi,
On Mon, 22 Apr 2019, Jeff King wrote:
Show 23 quoted lines
> On Wed, Jan 16, 2019 at 01:09:03PM -0600, Cameron Steffen wrote:
>
> > I have this feature idea for git. There should be a command that
> > effectively combines git add -p and git checkout -p so that I can
> > navigate changed hunks and either stage or discard them.
> >
> > There is already a SO question asking about this exactly...
> > https://stackoverflow.com/questions/11538650/simultaneously-git-add-p-and-git-checkout-p
> >
> > Has this been discussed before? Is this a reasonable request? If so, I
> > might look into contributing the change myself.
>
> This is something I've sometimes wanted, too. I don't think it would be
> _too_ hard to do by modifying the add-interactive code. Both of those
> operations are driven by the same code; see the %patch_modes hash in
> git-add--interactive.perl, which defines the various situations. You
> would need to modify the actual code to handle the tri-state (there is
> not just "yes, apply it" and "no, leave it alone", but now "apply /
> discard / skip"). But it seems do-able.
>
> If you do plan to work on it, be aware that the perl bits of
> add--interactive are being re-written in C. So it might make sense to
> target the new C implementation instead of modifying the perl.

The work on that is tracked in PRs 170-175 on https://github.com/gitgitgadget/git, i.e.

- https://github.com/gitgitgadget/git/pull/170
- https://github.com/gitgitgadget/git/pull/171
- https://github.com/gitgitgadget/git/pull/172
- https://github.com/gitgitgadget/git/pull/173
- https://github.com/gitgitgadget/git/pull/174
- https://github.com/gitgitgadget/git/pull/175

Ciao, Johannes

David Aguilar· Apr 28, 2019, 08:47 UTC · re: Cameron Steffen · lore

Re: Stage or discard a hunk at a time?

On Wed, Jan 16, 2019 at 01:09:03PM -0600, Cameron Steffen wrote:
Show 13 quoted lines
> Hello,
> 
> I have this feature idea for git. There should be a command that
> effectively combines git add -p and git checkout -p so that I can
> navigate changed hunks and either stage or discard them.
> 
> There is already a SO question asking about this exactly...
> https://stackoverflow.com/questions/11538650/simultaneously-git-add-p-and-git-checkout-p
> 
> Has this been discussed before? Is this a reasonable request? If so, I
> might look into contributing the change myself.
> 
> Cameron
Install Git Cola.

It's a powerful Git GUI with a keyboard-centric workflow. You can do this completely through keyboard shortcuts (or a mouse if you prefer).

Typically:
	$ git cola
	ctrl-k: focus the status widget
	j,k: navigate up/down the file list
	ctrl-s: stage files
	ctrl-u: revert files to index
	ctrl-j: focus the diff widget to operate at the line/hunk level
	j, k: move the cursor up/down lines, hold shift to select lines
	s: to stage selection, or current hunk if no lines are selected
	ctrl-u: revert the selection, or current hunk, to match the index
https://github.com/git-cola/git-cola
https://git-cola.github.io/downloads.html
-- 
David

← back to recent threads