{"thread":{"id":"23703","subject":"[PATCH] git-stash.txt: Add new example","startedAt":"2010-05-05T07:37:14Z","lastAt":"2010-05-07T16:11:44Z","messageCount":6,"participants":["jari.aalto@cante.net","Junio C Hamano","Jari Aalto","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"140970","messageId":"1273045035-7292-1-git-send-email-jari.aalto@cante.net","threadId":"23703","inReplyTo":null,"subject":"[PATCH] git-stash.txt: Add new example","fromName":"","fromEmail":"jari.aalto@cante.net","sentAt":"2010-05-05T07:37:14Z","receivedAt":"2010-05-05T07:37:14Z","isPatch":true,"sender":{"key":"jari.aalto@cante.net","avatar":"https://avatars.githubusercontent.com/u/34601?v=4"},"body":"From: Jari Aalto <jari.aalto@cante.net>\n\nAdd new example \"Saving selected files to stash\" thanks to\nideas by Johan Sageryd <j416@1616.se>.\n\nSigned-off-by: Jari Aalto <jari.aalto@cante.net>\n---\n Documentation/git-stash.txt |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 473889a..7d9f9e1 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -230,6 +230,18 @@ $ edit/build/test remaining parts\n $ git commit foo -m 'Remaining parts'\n ----------------------------------------------------------------\n \n+Saving selected files to stash::\n+\n+You can use `git stash save --keep-index` to put only selected files\n+into the stash. Let's suppose the files A, B, C and D are modified and\n+you want to stash only C and D:\n++\n+----------------------------------------------------------------\n+$ git status\t\t\t# Verify what's modified\n+$ git add A B\t\t\t# ...not these\n+$ git stash save --keep-index   # ...but stash all the others\n+----------------------------------------------------------------\n+\n Recovering stashes that were cleared/dropped erroneously::\n \n If you mistakenly drop or clear stashes, they cannot be recovered\n-- \n1.7.0\n"},{"id":"141004","messageId":"7v39y6jfmv.fsf@alter.siamese.dyndns.org","threadId":"23703","inReplyTo":"1273045035-7292-1-git-send-email-jari.aalto@cante.net","subject":"Re: [PATCH] git-stash.txt: Add new example","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-05T19:46:32Z","receivedAt":"2010-05-05T19:46:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"jari.aalto@cante.net writes:\n\n> From: Jari Aalto <jari.aalto@cante.net>\n>\n> Add new example \"Saving selected files to stash\" thanks to\n> ideas by Johan Sageryd <j416@1616.se>.\n>\n> Signed-off-by: Jari Aalto <jari.aalto@cante.net>\n> ---\n>  Documentation/git-stash.txt |   12 ++++++++++++\n>  1 files changed, 12 insertions(+), 0 deletions(-)\n>\n> diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\n> index 473889a..7d9f9e1 100644\n> --- a/Documentation/git-stash.txt\n> +++ b/Documentation/git-stash.txt\n> @@ -230,6 +230,18 @@ $ edit/build/test remaining parts\n>  $ git commit foo -m 'Remaining parts'\n>  ----------------------------------------------------------------\n>  \n> +Saving selected files to stash::\n> +\n> +You can use `git stash save --keep-index` to put only selected files\n> +into the stash. Let's suppose the files A, B, C and D are modified and\n> +you want to stash only C and D:\n> ++\n> +----------------------------------------------------------------\n> +$ git status\t\t\t# Verify what's modified\n> +$ git add A B\t\t\t# ...not these\n> +$ git stash save --keep-index   # ...but stash all the others\n> +----------------------------------------------------------------\n> +\n\nWhile the above is not _wrong_ per-se, it was somewhat hard to understand\nfor me without a description on _why_ you might want to do this.  It\ndidn't help that \"put only selected files\" really meant \"get rid of\nselected _changes_ from the working tree and the index temporarily\".\n\nI'd perhaps suggest rephrasing it like this:\n\n        Sifting the Wheat from the Chaff::\n\n        When you have changes to the working tree that mix what are\n        necessary for the immediate task at hand, and what are needed\n        later but not right now, you can first `git add` only the former\n        and use `git stash save --keep-index` to get rid of the latter.\n        The latter is temporarily stored in the stash.  \n\n        Suppose you have changes to file A, B, and C, but only the half of\n        changes to file A and C are necessary for what you are doing:\n\n        $ git reset                     # make the index clean\n        $ git add -p A C                # add necessary bits to the index\n        $ git stash save --keep-index   # the remainder goes to the stash\n        ... test, debug, perfect ...\n        $ git commit\n        $ git stash pop                 # get the remainder back\n        ... and continue to work ...\n"},{"id":"141050","messageId":"87pr194e3v.fsf_-_@jondo.cante.net","threadId":"23703","inReplyTo":"7v39y6jfmv.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2] git-stash.txt: Add example \"Using stash selectively\"","fromName":"Jari Aalto","fromEmail":"jari.aalto@cante.net","sentAt":"2010-05-06T08:40:52Z","receivedAt":"2010-05-06T08:40:52Z","isPatch":true,"sender":{"key":"jari.aalto@cante.net","avatar":"https://avatars.githubusercontent.com/u/34601?v=4"},"body":"Add a new example to demonstrate the use of --keep-index.\nIdea by Johan Sageryd <j416@1616.se>.\n\nSigned-off-by: Jari Aalto <jari.aalto@cante.net>\n---\n Documentation/git-stash.txt |   16 ++++++++++++++++\n 1 files changed, 16 insertions(+), 0 deletions(-)\n\n\n> While the above is not _wrong_ per-se, it was somewhat hard to understand\n> for me without a description on _why_ you might want to do this.  It\n> didn't help that \"put only selected files\" really meant \"get rid of\n> selected _changes_ from the working tree and the index temporarily\".\n\nThis demonstrates the difference between the end-user and developer. The\nend-used think in term of tangible objects: \"I have files, I need to\nstash some of them\".\n\n> I'd perhaps suggest rephrasing it like this:\n>\n>         Sifting the Wheat from the Chaff::\n\nAs a non-native, to my regret, I'm unable to compherend this Heading, my\nsuggestion in patch v2:\n\n    \"Using stash selectively\"\n\n>         When you have changes to the working tree that mix what are\n>         necessary for the immediate task at hand, and what are needed\n>         later but not right now, you can first `git add` only the former\n>         and use `git stash save --keep-index` to get rid of the latter.\n>         The latter is temporarily stored in the stash.  \n>\n>         Suppose you have changes to file A, B, and C, but only the half of\n>         changes to file A and C are necessary for what you are doing:\n>\n>         $ git reset                     # make the index clean\n>         $ git add -p A C                # add necessary bits to the index\n>         $ git stash save --keep-index   # the remainder goes to the stash\n>         ... test, debug, perfect ...\n>         $ git commit\n>         $ git stash pop                 # get the remainder back\n>         ... and continue to work ...\n\nI've rewritten the patch based on the comments. Please review.\n\nJari\n\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 473889a..b3fa1e7 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -243,6 +243,22 @@ grep commit | cut -d\\  -f3 |\n xargs git log --merges --no-walk --grep=WIP\n ----------------------------------------------------------------\n \n+Using stash selectively::\n+\n+The `--keep-index` option can be useful in a situation where you want\n+store some, but not all, files temporarily in the stash. Suppose you\n+have changes to file A, B, and C, but only the half of changes to file\n+A and C are necessary for what you are doing:\n++\n+----------------------------------------------------------------\n+$ git reset                     # make the index clean\n+$ git add -p A C                # add necessary bits to the index\n+$ git stash save --keep-index   # the remainder goes to the stash\n+... test, debug, perfect ...\n+$ git commit\n+$ git stash pop                 # get the remainder back\n+... and continue to work ...\n+----------------------------------------------------------------\n \n SEE ALSO\n --------\n-- \n1.7.0\n"},{"id":"141055","messageId":"4BE28624.70302@viscovery.net","threadId":"23703","inReplyTo":"87pr194e3v.fsf_-_@jondo.cante.net","subject":"Re: [PATCH v2] git-stash.txt: Add example \"Using stash selectively\"","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-05-06T09:04:36Z","receivedAt":"2010-05-06T09:04:36Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 5/6/2010 10:40, schrieb Jari Aalto:\n> +$ git reset                     # make the index clean\n> +$ git add -p A C                # add necessary bits to the index\n> +$ git stash save --keep-index   # the remainder goes to the stash\n\nIsn't \"the remainder goes to the stash\" wrong? I thought that both\nworktree changes and index go to stash; only that changes recorded in the\nindex are not undone in the index and worktree.\n\n> +... test, debug, perfect ...\n> +$ git commit\n> +$ git stash pop                 # get the remainder back\n\nAnd here both changes are unstashed, but since the changes that previously\nwere only in the index are already commited, it looks as if no index\nchanges were unstashed.\n\nThe distinction is important because if you 'stash --keep-index', but then\nchange your mind and 'reset --hard', you actually do *not* lose data\nbecause the index changes are still in the stash.\n\nOr spelled in a different way: you cannot undo the index changes and keep\nonly the worktree changes by 'stash --keep-index', 'reset --hard', 'stash\npop'.\n\n-- Hannes\n"},{"id":"141120","messageId":"87iq70w0wc.fsf_-_@jondo.cante.net","threadId":"23703","inReplyTo":"4BE28624.70302@viscovery.net","subject":"[PATCH v3] git-stash.txt: Add example \"Using stash selectively\"","fromName":"Jari Aalto","fromEmail":"jari.aalto@cante.net","sentAt":"2010-05-07T08:50:59Z","receivedAt":"2010-05-07T08:50:59Z","isPatch":true,"sender":{"key":"jari.aalto@cante.net","avatar":"https://avatars.githubusercontent.com/u/34601?v=4"},"body":"Add a new example to demonstrate the use of --keep-index.\nIdea by Johan Sageryd <j416@1616.se> and\nJohannes Sixt <j.sixt@viscovery.net>.\n\nSigned-off-by: Jari Aalto <jari.aalto@cante.net>\n---\n Documentation/git-stash.txt |   22 ++++++++++++++++++++++\n 1 files changed, 22 insertions(+), 0 deletions(-)\n\n\n    Johannes Sixt <j.sixt@viscovery.net> writes:\n\n    > Am 5/6/2010 10:40, schrieb Jari Aalto:\n    >\n    >> +$ git reset                     # make the index clean\n    >> +$ git add -p A C                # add necessary bits to the index\n    >> +$ git stash save --keep-index   # the remainder goes to the stash\n    >\n    > Isn't \"the remainder goes to the stash\" wrong? I thought that both\n    > worktree changes and index go to stash; only that changes recorded in the\n    > index are not undone in the index and worktree.\n    >\n    >> +... test, debug, perfect ...\n    >> +$ git commit\n    >> +$ git stash pop                 # get the remainder back\n    >\n    > And here both changes are unstashed, but since the changes that previously\n    > were only in the index are already commited, it looks as if no index\n    > changes were unstashed.\n    >\n    > The distinction is important because if you 'stash --keep-index', but then\n    > change your mind and 'reset --hard', you actually do *not* lose data\n    > because the index changes are still in the stash.\n    >\n    > Or spelled in a different way: you cannot undo the index changes and keep\n    > only the worktree changes by 'stash --keep-index', 'reset --hard', 'stash\n    > pop'.\n\n    Reworked based on comments. Let me know if more is needed.\n\n    Jari\n\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 473889a..bde5120 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -243,6 +243,28 @@ grep commit | cut -d\\  -f3 |\n xargs git log --merges --no-walk --grep=WIP\n ----------------------------------------------------------------\n \n+Using stash selectively::\n+\n+The `--keep-index` option can be useful in a situation where you want\n+store some, but not all, files temporarily in the stash. But keep in\n+mind that it still records the whole tree (unless --patch is\n+specified). If you `stash --keep-index', but then change your mind and\n+`reset --hard', you actually do *not* lose data because the index\n+changes are still in the stash.\n++\n+So if you don't plan to reset the following workflow may be handy.\n+Suppose you have changes to files A, B, C; you continue to edit A and\n+B, but want to stash C:\n++\n+----------------------------------------------------------------\n+$ git reset                     # make the index clean\n+$ git add -p A C                # add necessary bits to the index\n+$ git stash save --keep-index   # current index is left untouched\n+... test, debug, perfect ...\n+$ git commit\n+$ git stash pop                 # get the remainder back\n+... and continue to work ...\n+----------------------------------------------------------------\n \n SEE ALSO\n --------\n-- \n1.7.0\n"},{"id":"141126","messageId":"7v8w7vhetb.fsf@alter.siamese.dyndns.org","threadId":"23703","inReplyTo":"87pr194e3v.fsf_-_@jondo.cante.net","subject":"Re: [PATCH v2] git-stash.txt: Add example \"Using stash selectively\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-07T16:11:44Z","receivedAt":"2010-05-07T16:11:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jari Aalto <jari.aalto@cante.net> writes:\n\n>> While the above is not _wrong_ per-se, it was somewhat hard to understand\n>> for me without a description on _why_ you might want to do this.  It\n>> didn't help that \"put only selected files\" really meant \"get rid of\n>> selected _changes_ from the working tree and the index temporarily\".\n>\n> This demonstrates the difference between the end-user and developer. The\n> end-used think in term of tangible objects: \"I have files, I need to\n> stash some of them\".\n\nNot really.  You just demonstrated that you ignored \"partial add\".  It is\nnot so unusual for a user to need to express \"I have a file, and I have\ntwo kinds of changes to it.  The ones that I need now and the ones I need\nto postpone\".\n"}]}