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

Re: git commit -p with file arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 9, 2016, 18:03 UTC
Message-ID
<xmqq8tv1c5nb.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CA+P7+xoN+q_Kst=qXG_HRznxbN7cbyi5uZe15zq1c16EifeK1Q@mail.gmail.com>
Jacob Keller <jacob.keller@gmail.com> writes:
Show 6 quoted lines
> It wants to commit bar too because you already added bar before. It works like:
>
> "git add bar && git add -p foo && git commit" does it not?
>
> I fail to see why "git commit -p <path>" would unstage the bar you
> already added? Or am I missing some assumption here?
Yes.

"git commit -p <pathspec>" were added originally for lazy people who do not want to type "git add -p <pathspec> && git commit", which matches your expectation. If you already added "bar" that is outside of the <pathspec> given to "add -p", the final "git commit" step would record the latest contents of "bar" in it.

For obvious reasons, "git commit -p <pathspec>" cannot be a short-hand to "git add -p <pathspec> && git commit <pathspec>", so the current behaviour was the best they could do for those who aded "commit -p", I guess.

Previous: Christian NeukirchenNext: Jakub Narębski
Message 8 of 16 in “git commit -p with file arguments”
  1. Christian NeukirchenSep 5, 2016
  2. Duy NguyenSep 9, 2016
  3. Duy NguyenOct 5, 2016
  4. Christian NeukirchenOct 5, 2016
  5. Junio C HamanoOct 5, 2016
  6. Jacob KellerSep 9, 2016
  7. Christian NeukirchenSep 9, 2016
  8. Junio C HamanoSep 9, 2016
  9. Jakub NarębskiSep 9, 2016
  10. Christian NeukirchenSep 9, 2016
  11. Jakub NarębskiSep 10, 2016
  12. Junio C HamanoSep 11, 2016
  13. Jacob KellerSep 11, 2016
  14. Junio C HamanoSep 12, 2016
  15. Jacob KellerSep 12, 2016
  16. Jakub NarębskiSep 12, 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.