Search code examples
gitgit-rebasemerge-conflict-resolutiongit-merge-conflict

Reattempt conflict resolution during git rebase


I'm in the middle of a very large rebase, resolving conflicts as I go and using git rebase --continue.

Part way trying to resolve conflicts on multiple files, I realise I've made a bit of a mess of it. Is there an easy way I can go back to this stage of the rebase, before I started resolving conflicts?

Obviously I don't want to use git rebase --abort and lose all of the time that I've spent fixing other conflicts.

I found the following Stack Overflow question, but could do with some clearer steps:

How to rollback a single conflict resolution during git rebase

In particular, what does the -m flag do? Is path/to/wrong the name of the branch that I'm rebasing onto, the the branch that I'm rebasing or a reference to a particular commit?


Solution

  • To reset a single file to the un-merged version, do:

    git checkout --merge path/to/file
    

    If you know the commit hash for the original version of the commit that is currently being applied (if not, look in the reflog), you can automate the process for all files changed in that commit:

    #!/bin/bash
    
    for file in $(git show --pretty=format: --name-only 812b091)
    do
      git checkout --merge "$file"
    done
    

    From the git-checkout man page:

    -m, --merge

    [snip]

    When checking out paths from the index, this option lets you recreate the conflicted merge in the specified paths.