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

Re: "git commit --amend --only --" nevertheless commits staged changes

From
Jeff King <peff@peff.net>
Date
Jul 10, 2012, 20:30 UTC
Message-ID
<20120710203052.GB23798@sigill.intra.peff.net>
In-Reply-To
<7vwr2bgyqf.fsf@alter.siamese.dyndns.org>
On Tue, Jul 10, 2012 at 01:14:32PM -0700, Junio C Hamano wrote:
Show 8 quoted lines
> I do not think the combination with --amend, --only and no paths
> ever worked.  We rejected such a combination before 6a74642c5, which
> merely made us to accept the combination but I do not think the
> commit did anything to re-read the tree from the HEAD being amended
> to the index.
> 
> Something like this, but I haven't thought about what other things
> it may break.

Our emails just crossed. I came to the exact same conclusion, and just wrote almost the exact same patch.

> -	if (!pathspec || !*pathspec) {
> +	if (!(only && amend) && (!pathspec || !*pathspec)) {

It is sufficient to check only "only" in the first part of your conditional, as we disallow empty pathspecs with "-o". And even if we didn't disallow it, this would do the right thing by trying to create a partial commit with no changes (which would fail, of course, but is the only sane thing for the prepare_index function to do; certainly doing an as-is commit is simply wrong).

-Peff
Previous: Junio C HamanoNext: Jeff King
Message 4 of 5 in “"git commit --amend --only --" nevertheless commits staged changes”
  1. Marc StrapetzJul 10, 2012
  2. Jeff KingJul 10, 2012
  3. Junio C HamanoJul 10, 2012
  4. Jeff KingJul 10, 2012
  5. Jeff KingJul 10, 2012

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.