git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Pierre Habouzit <madcoder@madism.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Nanako Shiraishi <nanako3@lavabit.com>,
	Pierre Habouzit <madcoder@debian.org>,
	Thomas Rast <trast@student.ethz.ch>,
	git@vger.kernel.org
Subject: Re: [PATCH] git-add -p: be able to undo a given hunk
Date: Sun, 26 Jul 2009 11:39:50 -0400	[thread overview]
Message-ID: <20090726153950.GA16780@sigill.intra.peff.net> (raw)
In-Reply-To: <20090725145237.GB18545@artemis.corp>

On Sat, Jul 25, 2009 at 04:52:37PM +0200, Pierre Habouzit wrote:

> FWIW it's what I was doing so far, and it's not very efficient for many
> patterns, you talked about the bit where you want to keep some of the
> debug, for this one I used to do that:
> 
> while I have meaning full commits to do:
>     git add -p; commit;
> git add -p the things I want to trash and commit
> git stash
> git reset --hard HEAD~1
> git stash apply
> 
> That sucks.
> [...]
> For all those reasons I believe it's a good thing to be able to have
> something to remove hunks from the working-directory. Jeff's suggestions
> to move them to some stash is the best suggestion so far, and is safe.

Here's kind of a weird idea I've been considering. Feel free to write it
off as insane ranting.

My two complaints about using stash for separating changes are:

  - it lacks the tool support for splitting changes that we have for
    making commits (like "add -p"), and it lacks the ability to build up
    a set of changes over multiple commands (like we can do for commits)

  - it works as a single destination. You stash and delete a change from
    the working tree, or you leave it. It's hard to say "there are 3
    different types of change here" and sort them all at once.

My idea is to instead have a general set of "registers" that contain
states, each of which is basically an index. You can copy state from
register to register, from working tree to register, or from register to
register. You can also do any of those moves by looking at differences
between two states and saying "move this change" (i.e., like what "add
-p" does for the regular index).

So one way of splitting changes would be to say:

  1. Set registers 'a' and 'b' to the same state as HEAD

  2. Pick changes from the working tree to go to 'a'

  3. Pick changes from the working tree to go to 'b'

  4. Commit 'a' on top of HEAD

  5. Commit 'b' on top of new HEAD (and this would probably actually
     mean the changes from 'b' to the old HEAD, not setting the new HEAD
     state to what's in 'b').

So it's sort of a generalized form of the index, where you have N "index
registers" and you sort your changes into them. And during steps 2 and
3, you could also make more changes, pick them out, etc.

The workflow you want maps into that pretty simply: you would sort your
changes into "stuff you want to commit" and "stuff that is debugging
cruft". And then you would just throw away the latter register (or use a
special "trash" register).

And the workflow I described is "pick the changes for 'a', then for
'a'". But there's no reason you couldn't go through the changes, sorting
each into "put this one into 'a', and this one into 'b'". Which is what
you asked for.

Is this really that different from what you proposed? No, I don't really
think so in terms of implementation, but it is really about a different
mental model:

  1. You never delete things. You only copy or move them into registers.

  2. The interface should be the same whether you are moving between
     registers, or to/from the working tree.

  3. It extends naturally to multiple registers.

Anyway, just some stray thoughts. No code, so feel free to ignore. ;)

-Peff

  reply	other threads:[~2009-07-26 15:40 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-23  7:41 [PATCH] git-add -p: be able to undo a given hunk Pierre Habouzit
2009-07-23  8:41 ` Thomas Rast
2009-07-23  8:50   ` Pierre Habouzit
2009-07-24  9:15   ` [RFC PATCH] Implement unstage and reset modes for git-add--interactive Thomas Rast
2009-07-24 16:24     ` [RFC PATCH v2 1/3] Introduce git-unstage Thomas Rast
2009-07-24 17:59       ` Bert Wesarg
2009-07-24 18:02         ` Bert Wesarg
2009-07-24 18:23       ` Elijah Newren
2009-07-24 16:24     ` [RFC PATCH v2 2/3] Introduce git-discard Thomas Rast
2009-07-24 18:02       ` Elijah Newren
2009-07-24 18:12         ` Bert Wesarg
2009-07-24 18:24           ` Elijah Newren
2009-07-25 14:58       ` Pierre Habouzit
2009-07-24 16:24     ` [RFC PATCH v2 3/3] Implement unstage --patch and discard --patch Thomas Rast
2009-07-24 16:40       ` Matthias Kestenholz
2009-07-24 18:08       ` Bert Wesarg
2009-07-24 16:39     ` [RFC PATCH] Implement unstage and reset modes for git-add--interactive Junio C Hamano
2009-07-24 21:58       ` Nanako Shiraishi
2009-07-24 23:17         ` Thomas Rast
2009-07-24 23:25         ` Junio C Hamano
2009-07-25 21:29           ` [RFC PATCH v3 0/5] {checkout,reset,stash} --patch Thomas Rast
2009-07-25 21:29             ` [RFC PATCH v3 1/5] git-apply--interactive: Refactor patch mode code Thomas Rast
2009-07-25 21:29             ` [RFC PATCH v3 2/5] builtin-add: refactor the meat of interactive_add() Thomas Rast
2009-07-25 21:29             ` [RFC PATCH v3 3/5] Implement 'git reset --patch' Thomas Rast
2009-07-25 21:29             ` [RFC PATCH v3 4/5] Implement 'git checkout --patch' Thomas Rast
2009-07-25 21:29             ` [RFC PATCH v3 5/5] Implement 'git stash save --patch' Thomas Rast
2009-07-26  6:03               ` Sverre Rabbelier
2009-07-26  8:45                 ` Thomas Rast
2009-07-27 10:10             ` [RFC PATCH v3 0/5] {checkout,reset,stash} --patch Thomas Rast
2009-07-28 21:20               ` [PATCH v4 " Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 1/5] git-apply--interactive: Refactor patch mode code Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 2/5] builtin-add: refactor the meat of interactive_add() Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 3/5] Implement 'git reset --patch' Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 4/5] Implement 'git checkout --patch' Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 5/5] Implement 'git stash save --patch' Thomas Rast
2009-07-28 21:20                 ` [PATCH v4 6/5] DWIM 'git stash save -p' for 'git stash -p' Thomas Rast
2009-08-09  6:52                 ` [PATCH v4 0/5] {checkout,reset,stash} --patch Jeff King
2009-08-09  9:17                   ` Thomas Rast
2009-08-09 16:32                     ` [PATCH v4 0/5] " Nicolas Sebrecht
2009-08-09 16:44                       ` Thomas Rast
2009-08-09 21:28                         ` Nicolas Sebrecht
2009-08-09 21:42                           ` Thomas Rast
2009-08-09 22:26                             ` Nicolas Sebrecht
2009-08-10  9:36                               ` Thomas Rast
2009-08-13 12:29                                 ` [PATCH v5 0/6] " Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 1/6] git-apply--interactive: Refactor patch mode code Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 2/6] Add a small patch-mode testing library Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 3/6] builtin-add: refactor the meat of interactive_add() Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 4/6] Implement 'git reset --patch' Thomas Rast
2009-08-15 11:48                                     ` [PATCH v5.1 " Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 5/6] Implement 'git checkout --patch' Thomas Rast
2009-08-15 11:48                                     ` [PATCH v5.1 " Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 6/6] Implement 'git stash save --patch' Thomas Rast
2009-08-13 12:29                                   ` [PATCH v5 7/6] DWIM 'git stash save -p' for 'git stash -p' Thomas Rast
2009-08-14 20:57                                   ` [PATCH v5 0/6] Re: {checkout,reset,stash} --patch Nicolas Sebrecht
2009-08-15  6:51                                   ` [PATCH v5 0/6] " Jeff King
2009-08-15  7:57                                     ` Junio C Hamano
2009-08-15 10:14                                       ` Thomas Rast
2009-08-15 10:04                                     ` Thomas Rast
2009-08-18 16:48                                       ` Jeff King
2009-08-19  9:40                                         ` Thomas Rast
2009-08-19 10:11                                           ` Jeff King
2009-07-23 19:58 ` [PATCH] git-add -p: be able to undo a given hunk Junio C Hamano
2009-07-24 10:32   ` Nanako Shiraishi
2009-07-24 16:06     ` Junio C Hamano
2009-07-24 17:06       ` Jeff King
2009-07-25  0:54         ` Junio C Hamano
2009-07-25  9:35           ` Thomas Rast
2009-07-25 14:48         ` Pierre Habouzit
2009-07-25 14:52       ` Pierre Habouzit
2009-07-26 15:39         ` Jeff King [this message]
2009-07-27  8:26           ` Pierre Habouzit
2009-07-27 10:30             ` Jeff King
2009-07-27 10:06           ` Thomas Rast
2009-07-27 10:36             ` Jeff King
2009-07-24 14:58   ` Pierre Habouzit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090726153950.GA16780@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=madcoder@debian.org \
    --cc=madcoder@madism.org \
    --cc=nanako3@lavabit.com \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).