5

Is there a way to retrieve the commit from which a stash was originally created?

When creating a stash with the default command git stash the original commit is saved in the stash message, so it usually looks like:

stash@{0}: WIP on master: abc123 This is the message of some commit.

However, if git stash save 'a stash message' is used, the commit does not appear in the stash list:

stash@{1}: On master: my own message

So how could it be retrieved?

Maic López Sáenz
  • 10,385
  • 4
  • 44
  • 57

1 Answers1

5

I'd say

git log -1 commitish^

E.g.

git log -1 stash@{0}^

Otherwise,

git log -g --no-walk --parents refs/stash
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Ah, never though of `stash@{X}` as a reference. Works perfectly! – Maic López Sáenz Apr 17 '13 at 23:10
  • @LopSae It's not a reference, though, `refs/stash`, is. As you can see, stashes are saved on a "fake branch refs/stash" and the individual items are available as items in the reflog of that fake branch. – sehe Apr 18 '13 at 06:20
  • Thank you for this answer. Would you mind seeing if you can clarify on my similar question here? https://stackoverflow.com/q/62867041/470749 – Ryan Jul 12 '20 at 22:26