Search code examples
gitdiffgit-merge

How to continue a git merge where someone pushed by marking all files as "resolved"?


My friend

  • run git merge master
  • resolved some of the conflicts
  • marked all of the files as "resolved"
  • pushed the merge commit to a temp branch

I pulled the branch. I can see diff lines in the files like

<<<<<<< HEAD
text1
=======
text2
>>>>>>> origin/master

How can I simulate the merge where my friend left off?

I am ok with the solutions which include some pull/checkouts into other places, some copy/paste commands, other commands/tools to detect diff parts etc.


Solution

  • I would not try to recover from your friend's work, but rather redo the merge from scratch.

    Find your friend's merged commit and use git log --graph or git log --format=fuller to determine its parent commits:

    E.g., I have 39184c481a which is a merge of 2aa69455a3 into 1d3c2f45f6.

    git log --format=fuller 39184c481a
    
    commit 39184c481a
    Merge: 1d3c2f45f6 2aa69455a3
    Author: ...
    

    Then checkout the original first parent and merge the other parent into it

    git checkout 1d3c2f45f6
    git merge 2aa69455a3
    

    and now I'm in the same state I was when the commit was done. So from here you should be able to redo the conflict resolution.

    You probably want to give yourself a branch to be able to find this work later:

    git checkout -b dev.fixing-the-merge
    

    And eventually merge this back into your main branch, or possibly rewrite the history with a git push --force if your team is willing to let you do that.