How can we merge two stash in git , without commiting any of the stash?

Viewed 156

I have stash_one as stash@{1} and stash_two as stash@{2} . now if i do git stash apply stash@{1} then on my editor i will have all the changes which was in stash_one. But when i do git stash apply stash@{2} , then it says

Please commit your changes or stash them before you merge.

I dont want to merge it . I want to apply stash_two also , So that I can see both the changes of stash_one and stash_two at once. How can I do it?

2 Answers

You can consider committing each of them and then doing a squash with git rebase follow by a git push.

You can do the following for as many "stashes" as you have. The trick is to do git add . after each "pop" or "apply"

git stash apply stash@{1}
git add .
git stash apply stash@{2}
git reset .

You can reset single files from staging area with git reset <file> instead of resetting all files with git reset .

You can also use git stash pop for as many "stashes" as you have. In this case two stashes means two pops like:

git stash pop
git add .
git stash pop
git reset .
Related