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

Re: Bug in git-stash

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Apr 12, 2025, 16:29 UTC
Message-ID
<A17CFE85-47BD-4DD1-B377-8EA27A1262BA@gmail.com>
In-Reply-To
<AE8657E8-D68A-4B86-9644-B57AEE743794@gmail.com>
Hi!
> The stash contains the diff between HEAD and the unstaged file
This is expected behavior. From the git stash manpage:

""" All changes already added to the index are left intact. """

This is, it works just like running `git stash` but without touching the index and keeping the already staged changes in the working directory.

But still, each stash entry is two commits, one containing the state of the index and other containing the state of the working tree. You can see that in git stash manpage, in the section "DISCUSSION". This way, you can operate on them like any other commit.

More specifically, if you want the stashed changes from the index to the working directory, you can run:

git cherry-pick -n -m 2 stash
where:
-n: cherry-picks the content without creating a commit
-m 2: given that the last commit is a merge commit whose
  parents are the HEAD at the moment of stashing changes (the
  first parent) and the commit containing the state of the
  index (the second parent), apply the changes based on the
  second parent (i.e. what was in the working directory but
  not in the index)
- stash: this is the stash reference (just like any other
  reference, like branches or tags). It points to the last
  commit of the last stash entry. If you want to use other
  entry, follow the reflog syntax (i.e. stash@{1})
Previous: D. Ben Knoble
Message 3 of 3 in “Bug in git-stash”
  1. Filip SkogstjärnaApr 11, 2025
  2. D. Ben KnobleApr 11, 2025
  3. Lucas Seiki OshiroApr 12, 2025

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.