When I have to apply stashed changes to a dirty working copy, e.g. pop more than one changeset from the stash, I use the following:
$ git stash show -p | git apply -3 && git stash drop
Basically it
I wonder why there is no -f
(force) option for git stash pop
which should exactly behave like the one-liner above.
In the meantime you might want to add this one-liner as a git alias:
$ git config --global --replace-all alias.unstash \
'!git stash show -p | git apply -3 && git stash drop'
$ git unstash
Thanks to @SamHasler for pointing out the -3
parameter which allows to resolve conflicts directly via 3-way merge.
I do it in this way:
git add -A
git stash apply
and then (optionaly):
git reset
You can do this without having to stash your current changes by exporting the stash you want as a patch file and manually applying it.
For example, say you want to apply stash@{0} to a dirty tree:
Export stash@{0} as a patch:
git stash show -p stash@{0} > Stash0.patch
Manually apply the changes:
git apply Stash0.patch
If the second step fails, you will have to edit the Stash0.patch file to fix any errors and then try git apply again.
Either clean your working directory with git reset, commit the changes, or, if you want to stash the current changes, try:
$ git stash save "description of current changes" $ git stash pop stash@{1}
This will stash the current changes, and then pop the second stash from the stash stack.
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