{"thread":{"id":"37893","subject":"git commit --only -- $path when $path already has staged content","startedAt":"2014-11-07T10:38:16Z","lastAt":"2014-11-10T07:18:59Z","messageCount":5,"participants":["Stefan Näwe","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"251452","messageId":"545CA118.6040500@atlas-elektronik.com","threadId":"37893","inReplyTo":null,"subject":"git commit --only -- $path when $path already has staged content","fromName":"Stefan Näwe","fromEmail":"stefan.naewe@atlas-elektronik.com","sentAt":"2014-11-07T10:38:16Z","receivedAt":"2014-11-07T10:38:16Z","isPatch":false,"sender":{"key":"stefan.naewe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4468?v=4"},"body":"Hello.\n\nThe manpage of git commit reads:\n\n  --only\n\n      Make a commit only from the paths specified on the command line,\n      disregarding any contents that have been staged so far. This is\n      the default mode of operation of git commit if any paths are given\n      on the command line, in which case this option can be omitted. [...]\n\nBut that seems to be only true for other content (i.e. other files not\nspecified in the command line).\n\nIf I do:\n\n    # some repo with a file in it\n    git init\n    echo content >foo && git add foo && git commit -m foo\n\n    # modify and stage a file\n    echo other >> foo && git add foo\n\n    # modify the same file even further but don't stage\n    echo bar >> foo\n\n    # commit with path specified on command line with explicit '--only'\n    git commit --only -m'.' -- foo\n\n    # but everything was commited\n    git status -s\n    <empty>\n\nI would expect to only get the unstaged changes in the commit.\nCould anyone shed some light, please?\n\nThanks,\n  Stefan\n-- \n----------------------------------------------------------------\n/dev/random says: Useless Invention: Camcorder with braile-encoded buttons.\npython -c \"print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')\" \nGPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9  9666 829B 49C5 9221 27AF\n"},{"id":"251460","messageId":"xmqqmw83gd94.fsf@gitster.dls.corp.google.com","threadId":"37893","inReplyTo":"545CA118.6040500@atlas-elektronik.com","subject":"Re: git commit --only -- $path when $path already has staged content","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-07T16:57:11Z","receivedAt":"2014-11-07T16:57:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Näwe <stefan.naewe@atlas-elektronik.com> writes:\n\n> The manpage of git commit reads:\n>\n>   --only\n>\n>       Make a commit only from the paths specified on the command line,\n>       disregarding any contents that have been staged so far. This is\n>       the default mode of operation of git commit if any paths are given\n>       on the command line, in which case this option can be omitted. [...]\n\n\"--only\" is as opposed to \"--also\".  Two modes of partial commits\nare:\n\n - \"--also\" which updates the index with the whole contents of the\n   given paths and record the resulting index as the tree of the new\n   commit;\n\n - \"--only\" which starts from a new temporary index initialized from\n   HEAD with the whole contents of the given paths and record the\n   resulting index as the tree of the new commit, and then updates\n   the original index with the whole contents of the give paths.\n\nIn other words, you give paths from the command line to tell the\ncommand that you want to record the contents of them in the working\ntree as a whole to be recorded in the resulting commit.\n"},{"id":"251461","messageId":"xmqqioirgd7v.fsf@gitster.dls.corp.google.com","threadId":"37893","inReplyTo":"xmqqmw83gd94.fsf@gitster.dls.corp.google.com","subject":"Re: git commit --only -- $path when $path already has staged content","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-07T16:57:56Z","receivedAt":"2014-11-07T16:57:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Stefan Näwe <stefan.naewe@atlas-elektronik.com> writes:\n>\n>> The manpage of git commit reads:\n>>\n>>   --only\n>>\n>>       Make a commit only from the paths specified on the command line,\n>>       disregarding any contents that have been staged so far. This is\n>>       the default mode of operation of git commit if any paths are given\n>>       on the command line, in which case this option can be omitted. [...]\n>\n> \"--only\" is as opposed to \"--also\".  Two modes of partial commits\n> are:\n>\n>  - \"--also\" which updates the index with the whole contents of the\n>    given paths and record the resulting index as the tree of the new\n>    commit;\n>\n>  - \"--only\" which starts from a new temporary index initialized from\n>    HEAD with the whole contents of the given paths and record the\n>    resulting index as the tree of the new commit, and then updates\n>    the original index with the whole contents of the give paths.\n>\n> In other words, you give paths from the command line to tell the\n> command that you want to record the contents of them in the working\n> tree as a whole to be recorded in the resulting commit.\n\ns/also/include/; \"--also\" was its original name of the option while\nit was in development.\n"},{"id":"251505","messageId":"xmqq8ujmg51y.fsf@gitster.dls.corp.google.com","threadId":"37893","inReplyTo":"xmqqmw83gd94.fsf@gitster.dls.corp.google.com","subject":"Re: git commit --only -- $path when $path already has staged content","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-07T19:54:17Z","receivedAt":"2014-11-07T19:54:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> In other words, you give paths from the command line to tell the\n> command that you want to record the contents of them in the working\n> tree as a whole to be recorded in the resulting commit.\n\n... and --only/--include only makes difference wrt what happens to\ncontents from the other paths.\n\nPerhaps the attached would clarify it better, but there may have to\nbe some tutorial material to teach users that fundamentally there\nare two ways to use Git, one to prepare what to be committed in the\nindex and run \"git commit\" without any paths, and the other to\npretty much ignore the index and run \"git commit\" with paths (or\nwith \"-a\"), and mixing two are considered to be rare exception.\n\nYou would (1) work with an elaborate sequence to build the next\ncommit in the index using \"add path\" and \"add -p\", (2) notice a\nchange that can go before what you are building (e.g. trivial\ntypofix) outside the paths you are touching, and (3) edit that path\nand do \"git commit <path>\".  That is the only scenario that makes\nsome sense to mix the two modes.\n\nImagine the change (2) you want to jump over your changes in (1)\nhappens to be in a path you are working with the index, e.g. after\nrunning:\n\n\tgit add -p hello.rb\n\nand picking only parts of changes you made to hello.rb into the\nindex, you found a trivial typo in the same file but in an unrelated\nplace (i.e. \"git diff hello.rb\" at that point would not show the\ntypo either in the preimage or the context).  There is no way to\nmake the typofix first without disrupting what you did so far, and\n\"git commit -o\" would not help (you would instead do a \"git stash\"\nto save away the work in progress, make _only_ the typofix in the\nsame file, commit and then unstash, or something).\n\nSo in short, stick to either work with the index or ignore the\nindex; do not mix the two workflows and you would not have to worry\nabout \"-o\" or \"-i\".\n\n\n Documentation/git-commit.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 0bbc8f5..d6c4af1 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -250,7 +250,7 @@ FROM UPSTREAM REBASE\" section in linkgit:git-rebase[1].)\n \n -o::\n --only::\n-\tMake a commit only from the paths specified on the\n+\tMake a commit only from the working tree contents of the paths specified on the\n \tcommand line, disregarding any contents that have been\n \tstaged so far. This is the default mode of operation of\n \t'git commit' if any paths are given on the command line,\n"},{"id":"251659","messageId":"546066E3.3060708@atlas-elektronik.com","threadId":"37893","inReplyTo":"xmqq8ujmg51y.fsf@gitster.dls.corp.google.com","subject":"Re: git commit --only -- $path when $path already has staged content","fromName":"Stefan Näwe","fromEmail":"stefan.naewe@atlas-elektronik.com","sentAt":"2014-11-10T07:18:59Z","receivedAt":"2014-11-10T07:18:59Z","isPatch":false,"sender":{"key":"stefan.naewe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4468?v=4"},"body":"Am 07.11.2014 um 20:54 schrieb Junio C Hamano:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> In other words, you give paths from the command line to tell the\n>> command that you want to record the contents of them in the working\n>> tree as a whole to be recorded in the resulting commit.\n> \n> ... and --only/--include only makes difference wrt what happens to\n> contents from the other paths.\n> \n> Perhaps the attached would clarify it better, but there may have to\n> be some tutorial material to teach users that fundamentally there\n> are two ways to use Git, one to prepare what to be committed in the\n> index and run \"git commit\" without any paths, and the other to\n> pretty much ignore the index and run \"git commit\" with paths (or\n> with \"-a\"), and mixing two are considered to be rare exception.\n> \n> You would (1) work with an elaborate sequence to build the next\n> commit in the index using \"add path\" and \"add -p\", (2) notice a\n> change that can go before what you are building (e.g. trivial\n> typofix) outside the paths you are touching, and (3) edit that path\n> and do \"git commit <path>\".  That is the only scenario that makes\n> some sense to mix the two modes.\n> \n> Imagine the change (2) you want to jump over your changes in (1)\n> happens to be in a path you are working with the index, e.g. after\n> running:\n> \n> \tgit add -p hello.rb\n> \n> and picking only parts of changes you made to hello.rb into the\n> index, you found a trivial typo in the same file but in an unrelated\n> place (i.e. \"git diff hello.rb\" at that point would not show the\n> typo either in the preimage or the context).  There is no way to\n> make the typofix first without disrupting what you did so far, and\n> \"git commit -o\" would not help (you would instead do a \"git stash\"\n> to save away the work in progress, make _only_ the typofix in the\n> same file, commit and then unstash, or something).\n> \n> So in short, stick to either work with the index or ignore the\n> index; do not mix the two workflows and you would not have to worry\n> about \"-o\" or \"-i\".\n\n \nThanks for your explanation. Makes perfect sense.\n\n>  Documentation/git-commit.txt | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\n> index 0bbc8f5..d6c4af1 100644\n> --- a/Documentation/git-commit.txt\n> +++ b/Documentation/git-commit.txt\n> @@ -250,7 +250,7 @@ FROM UPSTREAM REBASE\" section in linkgit:git-rebase[1].)\n>  \n>  -o::\n>  --only::\n> -\tMake a commit only from the paths specified on the\n> +\tMake a commit only from the working tree contents of the paths specified on the\n>  \tcommand line, disregarding any contents that have been\n>  \tstaged so far. This is the default mode of operation of\n>  \t'git commit' if any paths are given on the command line,\n\nYep, why not. Makes it a little clearer.\n\n\nStefan\n-- \n----------------------------------------------------------------\n/dev/random says: For every vision there is an equal and opposite revision.\npython -c \"print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')\" \nGPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9  9666 829B 49C5 9221 27AF\n"}]}