How to combine multiple stashes in git
This worked for me.
stage the current changes (if nothing in unstaged, skip this step)
git add .
apply the stash you wish
git stash apply stash@{0}
stage the current changes
git add .
or
git add <stashed_filename>
Continue step 2&3 multiple times
then un stage everything
git reset
DONE!
A better way is to just use git stash show -p stash@{whatever} > stash-{whatever}.diff
and then use git apply
for each one.
You can only apply a stash if there are no conflicts with modified files in the working tree, so, first, ensure there are no modified files in git status
, if there are, commit them. Then do:
git stash apply stash@{1}
git commit -a
# Enter your commit message
git stash apply stash@{3}
Then you can either make a new commit, or amend the previous one to combine them. You may need to resolve merge conflicts after each apply.
Also, if you ever decide to use git stash pop
rather than apply
, note that stash@{3}
would become stash@{2}
since the first one was popped off.
It's a little involved, but this almost always works:
Pop the first stash
$ git stash pop
Temporarily commit the changes from the first stash
$ git add . && git commit -am 'WIP'
Pop the second stash
$ git stash pop
Undo the temporary commit, keeping the changes it introduced
$ git reset --soft HEAD^