8

If I am in a branch e.g. test and have some work. If I do a git stash and switch to master branch, if I do a git stash clear do I lose the work I saved in test? Or does each branch have a separate stash stack?

SQB
  • 3,926
  • 2
  • 28
  • 49
Jim
  • 18,826
  • 34
  • 135
  • 254

1 Answers1

11

No. Stashes are infact the reflog of a reference (sort of like a 'hidden branch', if you will): refs/stash

So,

  • git reflog refs/stash

    e41a1b8 refs/stash@{0}: WIP on master: 42092ec PoC
    

    is roughly equivalent to

    git stash list

    stash@{0}: WIP on master: 42092ec PoC
    

So there's only one "branch" containing all stashes.

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    As you suggested with the quotes around "branch" in the middle, `refs/stash` is not really a branch per se. (It *is* a reference, just as branches and tags are references; but so are notes.) `git stash branch ...` will let you change any given stash *into* a branch, though (by checking out the parent and then creating the new branch and applying the stash). So if you have a stash and decide it should become a branch, that's easy to do. – torek Oct 20 '13 at 21:26
  • @torek thanks for that addition. Would you believe I somehow always overlooked `git stash branch` :) Or perhaps my use of git predates that subcommand (?). Anyways, glad to have learned that. – sehe Oct 20 '13 at 21:30