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

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

From
Johannes Sixt <j.sixt@viscovery.net>
Date
May 6, 2010, 09:04 UTC
Message-ID
<4BE28624.70302@viscovery.net>
In-Reply-To
<87pr194e3v.fsf_-_@jondo.cante.net>
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'.

-- Hannes
Previous: Jari AaltoNext: Jari Aalto
Message 4 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.