All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jakub Narębski" <jnareb@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Jacob Keller <jacob.keller@gmail.com>
Cc: Christian Neukirchen <chneukirchen@gmail.com>,
	Git mailing list <git@vger.kernel.org>
Subject: Re: git commit -p with file arguments
Date: Fri, 9 Sep 2016 22:39:13 +0200	[thread overview]
Message-ID: <23de5ffe-eaf8-2d62-2202-f1bf6087d44b@gmail.com> (raw)
In-Reply-To: <xmqq8tv1c5nb.fsf@gitster.mtv.corp.google.com>

W dniu 09.09.2016 o 20:03, Junio C Hamano pisze:
> Jacob Keller <jacob.keller@gmail.com> writes:
> 
>> 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.

The 'obvious reasons' are that 

  $ git add -p <pathspec> && git commit <pathspec>

would not work as intended, that is it wouldn't create commit out of
HEAD and changes to <pathspec> created interactively in the index.
"git commit <pathspec>" is a shortcut to "git commit --only <pathspec>";
the git-commit(1) manpage explains (emphasis mine):

 -o
 --only
    Make a commit by taking the updated *working tree contents* of
    the paths specified on the command line, disregarding any contents
    that have been staged for other paths. [...]

Which means that with "git add -p <pathspec> && git commit <pathspec>",
the "git add -p <pathspec>" would carefully craft the <pathspec> state
in the index... and "git commit <pathspec>" would take worktree version
of <pathspec> for commit, ignoring what was in the index :-(

Currently there is no way to create commit out of subset of the index,
e.g. with "git commit :0:<path>"

Best,
-- 
Jakub Narębski

  reply	other threads:[~2016-09-09 20:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05 21:08 git commit -p with file arguments Christian Neukirchen
2016-09-09 10:54 ` Duy Nguyen
2016-10-05 10:26   ` Duy Nguyen
2016-10-05 11:38     ` Christian Neukirchen
2016-10-05 17:16     ` Junio C Hamano
2016-09-09 16:57 ` Jacob Keller
2016-09-09 17:05   ` Christian Neukirchen
2016-09-09 18:03   ` Junio C Hamano
2016-09-09 20:39     ` Jakub Narębski [this message]
2016-09-09 20:52       ` Christian Neukirchen
2016-09-10  9:52         ` Jakub Narębski
2016-09-11 21:50           ` Junio C Hamano
2016-09-11 22:05             ` Jacob Keller
2016-09-12  1:57               ` Junio C Hamano
2016-09-12  4:56                 ` Jacob Keller
2016-09-12 21:14                 ` Jakub Narębski

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=23de5ffe-eaf8-2d62-2202-f1bf6087d44b@gmail.com \
    --to=jnareb@gmail.com \
    --cc=chneukirchen@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.