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
Jeff King <peff@peff.net>
Date
Oct 20, 2016, 02:13 UTC
Message-ID
<20161020021323.tav5glu7xy4u7mtj@sigill.intra.peff.net>
In-Reply-To
<CA+P7+xprKV1Y7VShLR9uNgcpVdZk39xoTfkwiin1bVQYTe_TAA@mail.gmail.com>
On Wed, Oct 19, 2016 at 04:36:36PM -0700, Jacob Keller wrote:
Show 7 quoted lines
> >   # 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?

Correct. If you wanted to modify the working tree, too, use "git checkout -p HEAD^".

Show 10 quoted lines
> 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>"
I suspect both of those would complain about legitimate workflows.

I dunno. I do not ever use "git commit <file>" myself. I almost invariably use one of "git add -p" (to review changes as I add them) or "git add -u" (when I know everything is in good shape, such as after merge resolution; I'll sometimes just "git commit -a", too).

But it sounds like you want a third mode besides "--include" and "--only". Basically "commit what has been staged already, but restrict the commit to the paths I mentioned". Something like "--only-staged" or something. I do not think we would want to change the default from --only, but I could see a config option or something to select that behavior.

I suspect nobody has really asked for such a thing before because separate staging and "git commit <file>" are really two distinct workflows. Your pain comes from mix-and-matching them.

-Peff
Previous: Jacob KellerNext: Jacob Keller
Message 4 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.