It happens that information about a merge are lost after we do a stash. A usual merge and a stashed merge are compared below.
git merge release-2013-10-29
# Everything works, cool
git commit -am "Upgraded to release 2013-10-29"
git push origin dev
Result is as expected, a merge commit:
Here I am in a scenario where I need to stash the merge changes just in order to have a look at the previous-to-the-merge behaviour.
git merge release-2013-11-06
# Conflicts fixed, but detected inappropriate behaviour
git stash
git stash pop
git commit -am "Upgraded to release 2013-11-06"
git push origin dev
Result: this commit is not a "merge" anymore. We also lost all single authored commits contained by the merge, just like if I would have made all these changes.
So, shouldn't we stash anything when merging? How to avoid such behaviour then?
When you do a merge, git stores a reference to the branch you're merging in MERGE_HEAD
. But it seems like git stash
doesn't save the reference.
You can try to set the MERGE_HEAD
back to the commit which you were merging after applying the stash:
Suppose you're merging release-2013-11-06 branch onto master, and the last commit there is - 3be2c99
, then you can do:
git stash apply --index
git update-ref MERGE_HEAD 3be2c99
git status
# All conflicts fixed but you're still merging
# ....
Notice the usage of --index
while applying the stash. That is required to get the changes back in the index, else you will get the stashed changes only in the working tree.
P.S: Ideally you should avoid stashing your uncommitted merge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With