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

Re: git commit -p with file arguments

From
Duy Nguyen <pclouds@gmail.com>
Date
Sep 9, 2016, 10:54 UTC
Message-ID
<CACsJy8DOqoW8quz-6qSVR2+3aJau2V=qXCx_SoZvBpmU+9+Oxw@mail.gmail.com>
In-Reply-To
<87zinmhx68.fsf@juno.home.vuxu.org>

On Tue, Sep 6, 2016 at 4:08 AM, Christian Neukirchen <chneukirchen@gmail.com> wrote:

Show 34 quoted lines
> Hi,
>
> I noticed the following suprising behavior:
>
> % git --version
> git version 2.10.0
>
> % git add bar
> % git status -s
> A  bar
>  M foo
>
> % git commit -p foo
> [stage a hunk]
> ...
> # Explicit paths specified without -i or -o; assuming --only paths...
> # On branch master
> # Changes to be committed:
> #       new file:   bar
> #       modified:   foo
> #
>
> So why does it want to commit bar too, when I explicitly wanted to
> commit foo only?
>
> This is not how "git commit files..." works, and the man page says
>
>             3.by listing files as arguments to the commit command, in which
>            case the commit will ignore changes staged in the index, and
>            instead record the current content of the listed files (which must
>            already be known to Git);
>
> I'd expect "git commit -p files..." to work like
> "git add -p files... && git commit files...".

The paths after '-p' could mean two things, either as a filter (e.g. like in "git add -p") to help save your time going through all changed files, or as "git commit files...". I think the paths were meant to be filter when '-p' was added. There's a separate bullet point git-commit man page, number 5, in about --patch, so that paragraph you quoted is probably _not_ about --patch. Either way changing its behavior now might surprise users used to it.

At the least I think we should clarify this in the document. Maybe we could add --patch-only as well, which commits just what you select in --patch mode, ignoring anything in existing index.

-- 
Duy
Previous: Christian NeukirchenNext: Duy Nguyen
Message 2 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.