Search code examples
git-rebase

How to do a difficult rebase in O(n) rather than O(n^2)?


There's this difficult rebase that keeps stumbling on conflicts every other commit. In order to be able to resolve some confusing conflicts, I must sometimes --abort and check out the master branch to see what exactly is there (unconfounded by conflict markup, stuff rebased so far, or git's "ours" vs. "theirs" hell). Whenever I do this, I must subsequently re-resolve all conflicts up to that point. This makes the rebase effectively O(n^2).

Is there a better way?

(Note: it absolutely must be a rebase, this requirement is a given. Merging is out of the question).


Solution

  • First, the new (Git 2.30) new merge strategy: ORT ("Ostensibly Recursive's Twin") will be slightly faster.
    But the all process would still be not O(n).

    Second, do use the git worktree command in order to checkout master in a separate folder (without making a separate clone).
    That way, you don't have to abort the merge in progress, and can compare with a copy of your working tree, on master branch.