3

I'm aware that git stashs are local only and the message will not be exposed to any remote party and the message is thus much less relevant than commit messages.

I don't seem to find a way to get the message which has been explicitly passed to git stash save or any other way to retrieve it since git stash pop is not recorded in git reflog.

I often write information into the stash message why I stashed and how far the stashed implementation is, so they're pretty valuable to me.

I'm aware the using branching has a lot of advantages over using git stash with almost no downsides. I'm in the transition of getting the habit of no longer using git stash in favor of branches, however I already lost messages and would like to clarify this once.

My git stash pop output looks like

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   test

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (958d4b921e7f3e8faa9fd2ecb12af13250e1f739)
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177

1 Answers1

2

First, git stash save is now called git stash push since Git 2.16+ (Q4 2017)

You can see the message tested in t/t3903-stash.sh, using git stash list (but that is before a git stash pop)

git stash is still a shell script, and you can see that, when it creates the stash, it actually creates a commit:

    # create the stash
    if test -z "$stash_msg"
    then
        stash_msg=$(printf 'WIP on %s' "$msg")
    else
        stash_msg=$(printf 'On %s: %s' "$branch" "$stash_msg")
    fi
    w_commit=$(printf '%s\n' "$stash_msg" |
    git commit-tree $w_tree -p $b_commit -p $i_commit $untracked_commit_option) ||
die "$(gettext "Cannot record working tree state")"

It would then stands to reason that a git log is able to get back that commit message.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • More precisely, a stash is at least two, sometimes three, commits; but the name `stash` points specifically to this `$w_commit` one, which is the one with the stash name. So `git log -1 stash` before dropping, or `git log -1 ` after (provided the commit is not yet garbage-collected), will get you the message. – torek Apr 22 '18 at 16:55
  • @torek agreed, now that I give the source code a closer look ;) – VonC Apr 22 '18 at 16:56