23

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

3
  • 1
    There's a git stash show subcommand that seems like it would be useful here. Commented Jun 17, 2013 at 16:59
  • @gcbenison - i tried that in my branch and it shows three files. Then i switched to master and tried there and it shows the same three files. How can i see which branch they are stashed in? Are stashes linked to a specific branch? Commented Jun 18, 2013 at 8:20
  • 1
    Stashes are not linked to any branch. Commented Jun 18, 2013 at 13:04

2 Answers 2

41

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.

Sign up to request clarification or add additional context in comments.

Comments

11

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 

1 Comment

I'd like to add (at least on windows) using quotes, "$stashes" preserves the newlines.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.