Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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?

like image 558
Ankit Kumar Avatar asked Oct 21 '25 00:10

Ankit Kumar


2 Answers

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 .
like image 68
caramba Avatar answered Oct 22 '25 13:10

caramba


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

like image 38
astrochun Avatar answered Oct 22 '25 14:10

astrochun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!