git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Marc Strapetz <marc.strapetz@syntevo.com>
Cc: git@vger.kernel.org
Subject: Re: "git commit --amend --only --" nevertheless commits staged changes
Date: Tue, 10 Jul 2012 16:11:25 -0400	[thread overview]
Message-ID: <20120710201125.GA23798@sigill.intra.peff.net> (raw)
In-Reply-To: <4FFC06C9.5050405@syntevo.com>

On Tue, Jul 10, 2012 at 12:41:13PM +0200, Marc Strapetz wrote:

> When using "git commit --amend --only --message <message> --", I'd
> expect to have just the commit message of my last commit changed,
> according to the man page:
> 
> "--only Make a commit only from the paths specified on the command line,
> disregarding any contents that have been staged so far. [...] If this
> option is specified together with --amend, then no paths need to be
> specified, which can be used to amend the last commit without committing
> changes that have already been staged."
> 
> However, all staged changes are committed as well. So looks like either
> the man page or Git is wrong here!?

I think git has a bug. As far as I can tell, this has never worked as
the documentation advertised. We originally forbid the use of "--only"
without paths as nonsensical. This was loosened by 6a74642 (git-commit
--amend: two fixes., 2006-04-20) to let "--amend --only --", but I don't
think it even worked then.

Using this test:

  git init repo &&
  cd repo &&
  echo "foo one" >foo &&
  echo "bar one" >bar &&
  git add . &&
  git commit -m one &&
  echo "foo two" >foo &&
  echo "bar two" >bar &&
  git add foo &&
  GIT_EDITOR=true git commit --amend -o &&
  git cat-file -p HEAD:foo &&
  git cat-file -p HEAD:bar

I always get:

  foo two
  bar one

i.e., we accidentally amend the commit with the staged contents in the
index. I get the same results for 6a74642 and on. If you switch the
commit to "-o bar", it does work properly (you get the updated "bar",
but the staged "foo" in the index is ignored).

-Peff

  reply	other threads:[~2012-07-10 20:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-10 10:41 "git commit --amend --only --" nevertheless commits staged changes Marc Strapetz
2012-07-10 20:11 ` Jeff King [this message]
2012-07-10 20:14 ` Junio C Hamano
2012-07-10 20:30   ` Jeff King
2012-07-10 20:40     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120710201125.GA23798@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=marc.strapetz@syntevo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).