git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] git-stash.txt: Add example "Using stash selectively"

From
Jari Aalto <jari.aalto@cante.net>
Date
May 6, 2010, 08:40 UTC
Message-ID
<87pr194e3v.fsf_-_@jondo.cante.net>
In-Reply-To
<7v39y6jfmv.fsf@alter.siamese.dyndns.org>

Add a new example to demonstrate the use of --keep-index. Idea by Johan Sageryd <j416@1616.se>.

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 Documentation/git-stash.txt |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
> While the above is not _wrong_ per-se, it was somewhat hard to understand
> for me without a description on _why_ you might want to do this.  It
> didn't help that "put only selected files" really meant "get rid of
> selected _changes_ from the working tree and the index temporarily".

This demonstrates the difference between the end-user and developer. The end-used think in term of tangible objects: "I have files, I need to stash some of them".

> I'd perhaps suggest rephrasing it like this:
>
>         Sifting the Wheat from the Chaff::

As a non-native, to my regret, I'm unable to compherend this Heading, my suggestion in patch v2:

    "Using stash selectively"
Show 16 quoted lines
>         When you have changes to the working tree that mix what are
>         necessary for the immediate task at hand, and what are needed
>         later but not right now, you can first `git add` only the former
>         and use `git stash save --keep-index` to get rid of the latter.
>         The latter is temporarily stored in the stash.  
>
>         Suppose you have changes to file A, B, and C, but only the half of
>         changes to file A and C are necessary for what you are doing:
>
>         $ 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
>         ... test, debug, perfect ...
>         $ git commit
>         $ git stash pop                 # get the remainder back
>         ... and continue to work ...
I've rewritten the patch based on the comments. Please review.
Jari
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 473889a..b3fa1e7 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -243,6 +243,22 @@ 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. Suppose you
+have changes to file A, B, and C, but only the half of changes to file
+A and C are necessary for what you are doing:
++
+----------------------------------------------------------------
+$ 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
+... test, debug, perfect ...
+$ git commit
+$ git stash pop                 # get the remainder back
+... and continue to work ...
+----------------------------------------------------------------
 
 SEE ALSO
 --------
-- 
1.7.0
Previous: Junio C HamanoNext: Johannes Sixt
Message 3 of 6 in “git-stash.txt: Add new example”
  1. git-stash.txt: Add new examplejari.aalto@cante.net, May 5, 2010
  2. Junio C HamanoMay 5, 2010
  3. git-stash.txt: Add example "Using stash selectively"Jari Aalto, May 6, 2010
  4. Johannes SixtMay 6, 2010
  5. git-stash.txt: Add example "Using stash selectively"Jari Aalto, May 7, 2010
  6. Junio C HamanoMay 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.