`git stash` during a merge conflict

前端 未结 5 936
猫巷女王i
猫巷女王i 2021-02-02 08:46

We\'ve done something bad.

We ran git stash save during a merge conflict, and now we can\'t restore our work.

Things we\'ve tried:

g         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 09:10

    The issue seems to be that git stash doesn't save a reference to the branch you were trying to merge in. During a merge, this is stored in a ref named MERGE_HEAD.

    To fix it and get back to your previous state, you need to find the revision (let's pretend it's d7a9884a380f81b2fbf002442ee9c9eaf34ff68d) you were trying to merge in, and set MERGE_HEAD to it after you apply the stash.

    Then you can apply the stash (with --index to re-stage everything that was staged before), and set your MERGE_HEAD:

    git stash apply --index
    git update-ref MERGE_HEAD d7a9884a380f81b2fbf002442ee9c9eaf34ff68d
    

提交回复
热议问题