home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] can "git stash show" distinguish between staged and unstaged stash content?

  • Subject: Re: [OCLUG-Tech] can "git stash show" distinguish between staged and unstaged stash content?
  • From: Alex Pilon <alp [ at ] alexpilon [ dot ] ca>
  • Date: Thu, 24 Sep 2015 11:23:13 -0400
On Thu, Sep 24, 2015 at 09:30:49AM -0400, Robert P. J. Day wrote:
>   i'm sure there must be a simple answer to this -- given that "git
> stash" will stash both the currently staged and unstaged content, is
> there some variation of "git stash show -p" that will distinguish
> between the content that was staged versus that which was unstaged?

Short answer, `git show stash^2` to see the index, and `git show stash`
for the WIP.

You can't show this using git-stash itself AFAIK.

The second of the two parents of the stash ref is the index. The ref
itself is the WIP.

    $ git log --graph --oneline --decorate --all
    […]
    *   7674f90 (refs/stash) WIP on rebasing: f831adb Persistent clipboard support.
    |\
    | * db95613 index on rebasing: f831adb Persistent clipboard support.
    |/
    * f831adb (rebasing, alp) Persistent clipboard support.

So somehash1 would be reachable by somehash0^2. On could also

    stash^{/index on}

Of course, somebody could do something unusual and have a commit message
that starts with "index on". Now what?

If you really didn't trust the index commit to always be the second, but
potentially the first, you could do something crazy like

    git show $(git rev-list $(git rev-list '^stash~2' 'stash^@' \
                 | tr '\n' _ \
                 | sed 's/_/.../' \
                 | tr -d _))

But I doubt there would ever be a need for that.