问题
I have the master branch on which I stashed multiple changes and now I want to create a new branch from the stashed changes which are at {0}. But I doubt that creation of the new branch will not affect my other stashes, because git
will drop my stash after creation of the new branch. Will git
only drop stashes at {0} index or will it drop all of the stashes? The stashed changes are too IMP for me.
回答1:
Short answer : No worries, stash entries are independent from one another. Go for it.
Case study with a visual representation
To help picture it, the stash can be viewed as a list of unrelated commits, each pointing to different points in the repo tree.
See on the Hypothetical situation below
F---G <<< feature/abc
/
/ H---I <<< bugfix/123
/ / \
A---B---C---D---E---F---J <<< master
\
\
K---L---M <<< feature/xyz
and the following Hypothetical scenario
You stashed changes a number of times during the last couple of days, while you were working on these different branches.
Let's say you stashed three times :
once on
feature/abc
during your first attempt at committingG
because you were unsatisfied with your first approach altogether but wanted to keep it at hand just in case.then you were interrupted while working on the bugfix/123, a bit after having committed
H
, and had to switch branches. Later you came back tobugfix/123
then did agit stash apply
rather thangit stash pop
to keep the entry alive in the stash for later reuse/inspection.
and finally
- had to stash again after
L
while working onfeature/xyz
(The operations happened in that order.)
Resulting stash situation
At this point your stash list would look like
stash@{0}: WIP on feature/xyz: f1d6b3a unfinished - get rid of var dumps
stash@{1}: WIP on hotfix/123: 94722ae unfinished - css still broken
stash@{2}: WIP on feature/abc: 4fb4785 no good - test T1 failed
but the important point is that, since a stash entry takes for parent whichever commit HEAD points to when the entry is made :
L
is the parent of f1d6b3a
(let's call it L'
)H
is the parent of 94722ae
(let's call it H'
)F
is the parent of 4fb4785
(let's call it F'
)
which, in the tree, could be pictured as
F' <<< stash@{2}
/
F---G <<< feature/abc H' <<< stash@{1}
/ /
/ H---I <<< bugfix/123
/ / \
A---B---C---D------------------E---F---J <<< master
\
\
K---L---M <<< feature/xyz
\
L' <<< stash@{0}
Then it's much easier to see that although they're listed sequentially in your stash list
, they're in fact unrelated.
来源:https://stackoverflow.com/questions/56898911/new-branch-from-git-stash-will-affect-other-stashes