简体   繁体   中英

Git stash: How to see if there are stashed changes in a branch

Let's say i'm in a branch off of master, called "my_new_stuff". I have a feeling i might have stashed something in there. I'm worried that if I do git stash pop and i didn't stash anything it's going to shove a load of unwanted crap into my working folder.

Can i see if there are stashed changes without unstashing them?

thanks, max

The stash stores snapshots in the same way that commits do. You can see the contents of the stash with

git stash list

You can reference those snapshots with the stash@{N} notation or use the hashes shown. You can use any of Git's commands that work on commits on stashes. For example

git diff master stash@{0}

will show you what the most recent stash would add/remove to the master branch if you applied it there.

Not quite an answer as such, but a little script I made using Peter Lundgren's answer, above, which i find very useful: when I switch branches it tells me if I have stashed changes.

in .git/hooks/post-checkout

#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
stashes=`git stash list | grep "WIP on $branch"`
if [ "$stashes" ]
then
  echo "You have the following stashes for this branch:"
  echo $stashes
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM