* git commit --only -- $path when $path already has staged content
@ 2014-11-07 10:38 Stefan Näwe
2014-11-07 16:57 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Näwe @ 2014-11-07 10:38 UTC (permalink / raw)
To: git@vger•kernel.org
Hello.
The manpage of git commit reads:
--only
Make a commit only from the paths specified on the command line,
disregarding any contents that have been staged so far. This is
the default mode of operation of git commit if any paths are given
on the command line, in which case this option can be omitted. [...]
But that seems to be only true for other content (i.e. other files not
specified in the command line).
If I do:
# some repo with a file in it
git init
echo content >foo && git add foo && git commit -m foo
# modify and stage a file
echo other >> foo && git add foo
# modify the same file even further but don't stage
echo bar >> foo
# commit with path specified on command line with explicit '--only'
git commit --only -m'.' -- foo
# but everything was commited
git status -s
<empty>
I would expect to only get the unstaged changes in the commit.
Could anyone shed some light, please?
Thanks,
Stefan
--
----------------------------------------------------------------
/dev/random says: Useless Invention: Camcorder with braile-encoded buttons.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"
GPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9 9666 829B 49C5 9221 27AF
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git commit --only -- $path when $path already has staged content
2014-11-07 10:38 git commit --only -- $path when $path already has staged content Stefan Näwe
@ 2014-11-07 16:57 ` Junio C Hamano
2014-11-07 16:57 ` Junio C Hamano
2014-11-07 19:54 ` Junio C Hamano
0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-11-07 16:57 UTC (permalink / raw)
To: Stefan Näwe; +Cc: git@vger•kernel.org
Stefan Näwe <stefan.naewe@atlas-elektronik•com> writes:
> The manpage of git commit reads:
>
> --only
>
> Make a commit only from the paths specified on the command line,
> disregarding any contents that have been staged so far. This is
> the default mode of operation of git commit if any paths are given
> on the command line, in which case this option can be omitted. [...]
"--only" is as opposed to "--also". Two modes of partial commits
are:
- "--also" which updates the index with the whole contents of the
given paths and record the resulting index as the tree of the new
commit;
- "--only" which starts from a new temporary index initialized from
HEAD with the whole contents of the given paths and record the
resulting index as the tree of the new commit, and then updates
the original index with the whole contents of the give paths.
In other words, you give paths from the command line to tell the
command that you want to record the contents of them in the working
tree as a whole to be recorded in the resulting commit.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git commit --only -- $path when $path already has staged content
2014-11-07 16:57 ` Junio C Hamano
@ 2014-11-07 16:57 ` Junio C Hamano
2014-11-07 19:54 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-11-07 16:57 UTC (permalink / raw)
To: Stefan Näwe; +Cc: git@vger•kernel.org
Junio C Hamano <gitster@pobox•com> writes:
> Stefan Näwe <stefan.naewe@atlas-elektronik•com> writes:
>
>> The manpage of git commit reads:
>>
>> --only
>>
>> Make a commit only from the paths specified on the command line,
>> disregarding any contents that have been staged so far. This is
>> the default mode of operation of git commit if any paths are given
>> on the command line, in which case this option can be omitted. [...]
>
> "--only" is as opposed to "--also". Two modes of partial commits
> are:
>
> - "--also" which updates the index with the whole contents of the
> given paths and record the resulting index as the tree of the new
> commit;
>
> - "--only" which starts from a new temporary index initialized from
> HEAD with the whole contents of the given paths and record the
> resulting index as the tree of the new commit, and then updates
> the original index with the whole contents of the give paths.
>
> In other words, you give paths from the command line to tell the
> command that you want to record the contents of them in the working
> tree as a whole to be recorded in the resulting commit.
s/also/include/; "--also" was its original name of the option while
it was in development.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git commit --only -- $path when $path already has staged content
2014-11-07 16:57 ` Junio C Hamano
2014-11-07 16:57 ` Junio C Hamano
@ 2014-11-07 19:54 ` Junio C Hamano
2014-11-10 7:18 ` Stefan Näwe
1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-11-07 19:54 UTC (permalink / raw)
To: Stefan Näwe; +Cc: git@vger•kernel.org
Junio C Hamano <gitster@pobox•com> writes:
> In other words, you give paths from the command line to tell the
> command that you want to record the contents of them in the working
> tree as a whole to be recorded in the resulting commit.
... and --only/--include only makes difference wrt what happens to
contents from the other paths.
Perhaps the attached would clarify it better, but there may have to
be some tutorial material to teach users that fundamentally there
are two ways to use Git, one to prepare what to be committed in the
index and run "git commit" without any paths, and the other to
pretty much ignore the index and run "git commit" with paths (or
with "-a"), and mixing two are considered to be rare exception.
You would (1) work with an elaborate sequence to build the next
commit in the index using "add path" and "add -p", (2) notice a
change that can go before what you are building (e.g. trivial
typofix) outside the paths you are touching, and (3) edit that path
and do "git commit <path>". That is the only scenario that makes
some sense to mix the two modes.
Imagine the change (2) you want to jump over your changes in (1)
happens to be in a path you are working with the index, e.g. after
running:
git add -p hello.rb
and picking only parts of changes you made to hello.rb into the
index, you found a trivial typo in the same file but in an unrelated
place (i.e. "git diff hello.rb" at that point would not show the
typo either in the preimage or the context). There is no way to
make the typofix first without disrupting what you did so far, and
"git commit -o" would not help (you would instead do a "git stash"
to save away the work in progress, make _only_ the typofix in the
same file, commit and then unstash, or something).
So in short, stick to either work with the index or ignore the
index; do not mix the two workflows and you would not have to worry
about "-o" or "-i".
Documentation/git-commit.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 0bbc8f5..d6c4af1 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -250,7 +250,7 @@ FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
-o::
--only::
- Make a commit only from the paths specified on the
+ Make a commit only from the working tree contents of the paths specified on the
command line, disregarding any contents that have been
staged so far. This is the default mode of operation of
'git commit' if any paths are given on the command line,
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: git commit --only -- $path when $path already has staged content
2014-11-07 19:54 ` Junio C Hamano
@ 2014-11-10 7:18 ` Stefan Näwe
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Näwe @ 2014-11-10 7:18 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git@vger•kernel.org
Am 07.11.2014 um 20:54 schrieb Junio C Hamano:
> Junio C Hamano <gitster@pobox•com> writes:
>
>> In other words, you give paths from the command line to tell the
>> command that you want to record the contents of them in the working
>> tree as a whole to be recorded in the resulting commit.
>
> ... and --only/--include only makes difference wrt what happens to
> contents from the other paths.
>
> Perhaps the attached would clarify it better, but there may have to
> be some tutorial material to teach users that fundamentally there
> are two ways to use Git, one to prepare what to be committed in the
> index and run "git commit" without any paths, and the other to
> pretty much ignore the index and run "git commit" with paths (or
> with "-a"), and mixing two are considered to be rare exception.
>
> You would (1) work with an elaborate sequence to build the next
> commit in the index using "add path" and "add -p", (2) notice a
> change that can go before what you are building (e.g. trivial
> typofix) outside the paths you are touching, and (3) edit that path
> and do "git commit <path>". That is the only scenario that makes
> some sense to mix the two modes.
>
> Imagine the change (2) you want to jump over your changes in (1)
> happens to be in a path you are working with the index, e.g. after
> running:
>
> git add -p hello.rb
>
> and picking only parts of changes you made to hello.rb into the
> index, you found a trivial typo in the same file but in an unrelated
> place (i.e. "git diff hello.rb" at that point would not show the
> typo either in the preimage or the context). There is no way to
> make the typofix first without disrupting what you did so far, and
> "git commit -o" would not help (you would instead do a "git stash"
> to save away the work in progress, make _only_ the typofix in the
> same file, commit and then unstash, or something).
>
> So in short, stick to either work with the index or ignore the
> index; do not mix the two workflows and you would not have to worry
> about "-o" or "-i".
Thanks for your explanation. Makes perfect sense.
> Documentation/git-commit.txt | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> index 0bbc8f5..d6c4af1 100644
> --- a/Documentation/git-commit.txt
> +++ b/Documentation/git-commit.txt
> @@ -250,7 +250,7 @@ FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
>
> -o::
> --only::
> - Make a commit only from the paths specified on the
> + Make a commit only from the working tree contents of the paths specified on the
> command line, disregarding any contents that have been
> staged so far. This is the default mode of operation of
> 'git commit' if any paths are given on the command line,
Yep, why not. Makes it a little clearer.
Stefan
--
----------------------------------------------------------------
/dev/random says: For every vision there is an equal and opposite revision.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"
GPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9 9666 829B 49C5 9221 27AF
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-11-10 7:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 10:38 git commit --only -- $path when $path already has staged content Stefan Näwe
2014-11-07 16:57 ` Junio C Hamano
2014-11-07 16:57 ` Junio C Hamano
2014-11-07 19:54 ` Junio C Hamano
2014-11-10 7:18 ` Stefan Näwe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox