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?
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?)
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.
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.
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?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With