I have stash two times, and I need to commit the two stash in one commit.
I use git stash apply
to apply the latest stash, but when I use it again, it throw below error,
error: Your local changes to the following files would be overwritten by merge: library/HQ/groupsql.sql Please commit your changes or stash them before you merge. Aborting The stash entry is kept in case you need it again.
How can I pop the two stash then commit them.
I think you can do the following:
// to see the list of "stashes" (like every time when stash run 'git stash' a new entry is created in the list
> git stash list
// Lest assume you need stash@{1} and stash@{3} for the sake of example
> git stash apply stash@{1}
git commit -am "Whatever message"
> git stash apply stash@{3}
git commit --amend // to add changes from stash3 from the previous commit
Bottom line, each stash apply once done produces commit on the local branch but you can alter the history as longs as the changes are local (not pushed)
I suggest you also to read This thread, it contains some neat trick, available since git 2.11: you can use git stash apply n
instead of git stash apply stash@{n}
Another advice: you can use git stash show stash@{3}
to see what files were changed in the stash 3 (if you're not sure which stash to apply)
I've never seen the feature of doing this in one command though. So for now my answer is "no, you can't apply multiple stashes at once". I'll be glad to be proven otherwise by more experienced git users.