Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I discover the git commit hash that I stashed from?

Tags:

git

I realize that my question is very similar to How to list the parent commit of a stash in `git stash list` and Get git stash parent commit, but those had so many confusing, disparate responses that I'm asking my own question.

Let's assume that if I run git stash list, I see stash@{0}: On featureX: someMessageHere

How can I reveal the hash of the commit that I was working from when I made that stash (which I guess could be considered a parent commit)?

I've seen so many different answers, and I'm confused about what these each do, how they are different, and which one is the answer to my question:

  • git show stash@{1}^
  • git log -1 commitish^
  • git log -1 stash@{0}^
  • git log -g --no-walk --parents refs/stash
  • git for-each-ref --format='%(refname:short)' --points-at $(git rev-parse refs/stash~1) refs/heads
git log -g --format="%gd %H" refs/stash |
while read name hash; do
    printf "%s %s " $name $(git rev-parse --short $name^)
    git log -1 --format=%s $hash
done

For extra context, this is the reason I'm asking.

like image 912
Ryan Avatar asked Dec 14 '22 08:12

Ryan


1 Answers

The commit you are looking for is stash@{0}^ :

git show stash@{0}^
git log -1 --oneline stash@{0}^
git rev-parse stash@{0}^
like image 115
LeGEC Avatar answered Dec 17 '22 23:12

LeGEC