Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does each branch have a separate stash?

Tags:

git

git-stash

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?

like image 429
Jim Avatar asked Oct 20 '13 19:10

Jim


People also ask

Does each branch have its own stash git?

So there's only one "branch" containing all stashes. The machinery might become more clear in this answer: Is it possible to push a git stash to a remote repository? you can 'deduce' what branch the stash fits onto by doing, e.g. (asking: what branches contain the parent revision for this stash?)

Does stash work per branch?

Stashing Your WorkYou can save a stash on one branch, switch to another branch later, and try to reapply the changes. You can also have modified and uncommitted files in your working directory when you apply a stash — Git gives you merge conflicts if anything no longer applies cleanly.

What is stash all in git?

Git stash is a built-in command with the distributed Version control tool in Git that locally stores all the most recent changes in a workspace and resets the state of the workspace to the prior commit state. A user can retrieve all files put into the stash with the git stash pop and git stash apply commands.


1 Answers

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.

  • The machinery might become more clear in this answer: Is it possible to push a git stash to a remote repository?

  • you can 'deduce' what branch the stash fits onto by doing, e.g.

    git branch -a --contains stash@{0}^
    

    (asking: what branches contain the parent revision for this stash?)

like image 107
sehe Avatar answered Sep 24 '22 03:09

sehe