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

Re: [RFC/PATCH 2/5] reset: add option "--keep" to "git reset"

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jan 19, 2010, 04:28 UTC
Message-ID
<201001190528.47414.chriscool@tuxfamily.org>
In-Reply-To
<7viqbk8evw.fsf@alter.siamese.dyndns.org>
On samedi 02 janvier 2010, Junio C Hamano wrote:
Show 32 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
> > The purpose of this new option is to discard some of the last commits
> > but to keep current changes in the work tree.
> >
> > The use case is when you work on something and commit that work. And
> > then you work on something else that touches other files, but you don't
> > commit it yet. Then you realize that what you commited when you worked
> > on the first thing is not good or belongs to another branch.
> >
> > So you want to get rid of the previous commits (at least in the current
> > branch) but you want to make sure that you keep the changes you have in
> > the work tree. And you are pretty sure that your changes are
> > independent from what you previously commited, so you don't want the
> > reset to succeed if the previous commits changed a file that you also
> > changed in your work tree.
> >
> > The table below shows what happens when running "git reset --option
> > target" to reset the HEAD to another commit (as a special case "target"
> > could be the same as HEAD) in the cases where "--merge" and "--keep"
> > behave differently.
>
> I think this new option is unrelated to "--merge"; iow, the only relation
> to it is that it is an option to the same command "git reset", so it is
> related but it is related the same way and to the degree as "--mixed" is.
>
> Thinking about it even more, if the number of commits you are resetting
> away is zero in your use case (i.e. target is HEAD), shouldn't this new
> mode of operation degenerate to "--mixed"?  So in that sense, it might
> make sense to contrast it with "--mixed".
>
> But let's try not to contrast it with anything else, and see how well it
> stands on its own. 

Ok, I removed parts of the commit messages that contrasted it with "--merge".

[...]
Show 14 quoted lines
> > The following table shows what happens on unmerged entries:
> >
> > working index HEAD target         working index HEAD
> > ----------------------------------------------------
> >  X       U     A    B     --keep  (disallowed)
> >  X       U     A    A     --keep   X       A     A
>
> In a sense, this is consistent with the above; the local change attempted
> happens to be an unmerged result.
>
> But it is inconsistent with the intended use case you presented, which
> leaves no room for unmerged entries to enter in the index to begin with.
> It might be safer to error out on any unmerged entry in the index.  I
> dunno.

Yeah I agree it might be safer, so I added a patch to disallow using --keep when there are unmerged entries.

Thanks, Christian.

Previous: Junio C HamanoNext: Christian Couder
Message 6 of 12 in “add "--keep" option to "git reset"”
  1. 0/5 add "--keep" option to "git reset"Christian Couder, Jan 2, 2010
  2. 1/5 reset: make "reset --merge" discard work tree changes on unmerged entriesChristian Couder, Jan 2, 2010
  3. Junio C HamanoJan 2, 2010
  4. 2/5 reset: add option "--keep" to "git reset"Christian Couder, Jan 2, 2010
  5. Junio C HamanoJan 2, 2010
  6. Christian CouderJan 19, 2010
  7. 3/5 reset: add test cases for "--keep" optionChristian Couder, Jan 2, 2010
  8. 4/5 Documentation: reset: describe new "--keep" optionChristian Couder, Jan 2, 2010
  9. Andreas SchwabJan 2, 2010
  10. Daniel ConvissorJan 2, 2010
  11. Christian CouderJan 19, 2010
  12. 5/5 reset: disallow "reset --keep" outside a work treeChristian Couder, Jan 2, 2010

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.