How to combine multiple stashes in git
Solution 1:
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^
Solution 2:
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.
Solution 3:
A better way is to just use git stash show -p stash@{whatever} > stash-{whatever}.diff
and then use git apply
for each one.