[PATCH v3] git-stash.txt: Add example "Using stash selectively"
- From
Jari Aalto <jari.aalto@cante.net>
- Date
- May 7, 2010, 08:50 UTC
- Message-ID
- <87iq70w0wc.fsf_-_@jondo.cante.net>
- In-Reply-To
- <4BE28624.70302@viscovery.net>
Add a new example to demonstrate the use of --keep-index. Idea by Johan Sageryd <j416@1616.se> and Johannes Sixt <j.sixt@viscovery.net>.
Signed-off-by: Jari Aalto <jari.aalto@cante.net> --- Documentation/git-stash.txt | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
Johannes Sixt <j.sixt@viscovery.net> writes:
> Am 5/6/2010 10:40, schrieb Jari Aalto:
>
>> +$ git reset # make the index clean
>> +$ git add -p A C # add necessary bits to the index
>> +$ git stash save --keep-index # the remainder goes to the stash
>
> Isn't "the remainder goes to the stash" wrong? I thought that both
> worktree changes and index go to stash; only that changes recorded in the
> index are not undone in the index and worktree.
>
>> +... test, debug, perfect ...
>> +$ git commit
>> +$ git stash pop # get the remainder back
>
> And here both changes are unstashed, but since the changes that previously
> were only in the index are already commited, it looks as if no index
> changes were unstashed.
>
> The distinction is important because if you 'stash --keep-index', but then
> change your mind and 'reset --hard', you actually do *not* lose data
> because the index changes are still in the stash.
>
> Or spelled in a different way: you cannot undo the index changes and keep
> only the worktree changes by 'stash --keep-index', 'reset --hard', 'stash
> pop'.Reworked based on comments. Let me know if more is needed.
Jari
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 473889a..bde5120 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -243,6 +243,28 @@ grep commit | cut -d\ -f3 | xargs git log --merges --no-walk --grep=WIP ---------------------------------------------------------------- +Using stash selectively:: + +The `--keep-index` option can be useful in a situation where you want +store some, but not all, files temporarily in the stash. But keep in +mind that it still records the whole tree (unless --patch is +specified). If you `stash --keep-index', but then change your mind and +`reset --hard', you actually do *not* lose data because the index +changes are still in the stash. ++ +So if you don't plan to reset the following workflow may be handy. +Suppose you have changes to files A, B, C; you continue to edit A and +B, but want to stash C: ++ +---------------------------------------------------------------- +$ git reset # make the index clean +$ git add -p A C # add necessary bits to the index +$ git stash save --keep-index # current index is left untouched +... test, debug, perfect ... +$ git commit +$ git stash pop # get the remainder back +... and continue to work ... +---------------------------------------------------------------- SEE ALSO --------
-- 1.7.0