How to combine multiple stashes in git

This worked for me.

  1. stage the current changes (if nothing in unstaged, skip this step)

    git add .
    
  2. apply the stash you wish

    git stash apply stash@{0}
    
  3. stage the current changes

    git add .
    

    or git add <stashed_filename>

  4. Continue step 2&3 multiple times

  5. 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:

  1. Pop the first stash

    $ git stash pop
    
  2. Temporarily commit the changes from the first stash

    $ git add . && git commit -am 'WIP'
    
  3. Pop the second stash

    $ git stash pop
    
  4. Undo the temporary commit, keeping the changes it introduced

    $ git reset --soft HEAD^
    

Tags:

Git

Git Stash