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

Re: tools for easily "uncommitting" parts of a patch I just commited?

From
Jacob Keller <jacob.keller@gmail.com>
Date
Oct 19, 2016, 23:36 UTC
Message-ID
<CA+P7+xprKV1Y7VShLR9uNgcpVdZk39xoTfkwiin1bVQYTe_TAA@mail.gmail.com>
In-Reply-To
<20161019224211.k4anavgqrhmunz6p@sigill.intra.peff.net>
On Wed, Oct 19, 2016 at 3:42 PM, Jeff King <peff@peff.net> wrote:
Show 22 quoted lines
> On Wed, Oct 19, 2016 at 03:26:18PM -0700, Jacob Keller wrote:
>
>> I recently (and in the past) had an issue where I was using git add
>> --interactive and accidentally did something like the following:
>>
>> # hack lots of randmo changes, then begin trying to commit then separately
>> git add -i
>> # set only the changes I want
>> # accidentally add <file> to the commit
>> $git commit -s <file>
>> # type up a long commit message
>> # notice that I committed everything
>>
>> At this point I'd like to be able to do something like:
>> $git unstage -i
>> # select each hunk to unstage
>
> I'd usually do one of:
>
>   # undo selectively
>   git reset -p HEAD^
>   git commit --amend

AHA! I knew about git reset -p but I didn't know about git reset -p allowed passing a treeish. Does this reset modify my local files at all? I think it doesn't, right?

Show 11 quoted lines
>
> or:
>
>   # roll back the whole commit
>   git reset HEAD
>   # do it right this time
>   git add -p
>   # and steal the commit message from the previous attempt
>   git commit -c HEAD@{1}
>
> -Peff
Also nice to know about git commit -c
Thanks a lot! This should save me some headaches.

I still think it's worth while to add a check for git-commit which does something like check when we say "git commit <files>" and if the index already has those files marked as being changed, compare them with the current contents of the file as in the checkout and quick saying "please don't do that" so as to avoid the problem in the first place.

A naive approach would just be "if index already has staged differences dont allow path selection" but that doesn't let me do something like "git add -p <files>" "git commit <other files>"

We could even make it work so that "commit --only" doesn't run this so that way people can easily override, and we can give suggestions for how to fix it in the output of the message. I can't really think if a reasonable objection to such a change. I'll try to code something up in the next few days when I can find some spare time.

Regards, Jake

Previous: Jeff KingNext: Jeff King
Message 3 of 16 in “tools for easily "uncommitting" parts of a patch I just commited?”
  1. Jacob KellerOct 19, 2016
  2. Jeff KingOct 19, 2016
  3. Jacob KellerOct 19, 2016
  4. Jeff KingOct 20, 2016
  5. Jacob KellerOct 20, 2016
  6. Junio C HamanoOct 20, 2016
  7. Jacob KellerOct 20, 2016
  8. Junio C HamanoOct 20, 2016
  9. Jacob KellerOct 20, 2016
  10. Junio C HamanoOct 20, 2016
  11. Jacob KellerOct 20, 2016
  12. Lukas FleischerOct 22, 2016
  13. Jacob KellerOct 23, 2016
  14. Duy NguyenOct 23, 2016
  15. Jeff KingOct 23, 2016
  16. Duy NguyenOct 23, 2016

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.