Search code examples
gitgit-mergerebasegit-rebase

git rebase and keep branches of rebased branch that has merges without manually resolving conflicts


When I have a git graph that lookslike this:

A - B - C
      \
        E - F - G - H
          \       /
            I - J

is it possible and if yes what commands do I need to use to come to a structure that is like this:

A - B - C - E - F - G - H
              \       /
                I - J

I have tried git rebase with lots of options but I haven't come to the result i want.

I tried with the --onto option but it creates a single branch and I need to solve conflict manually.


Solution

  • I found out that the actual way to do it and not have to resolve manually the conflicts is to use the rerere git's feature. The rerere is used to keep the conflicts resolutions and apply them when they are encountered again in a merge. There is a handfull script that is in the git repo called rerere-train.sh to train manually the rerere with merge conflicts resolutions from past merge commits.

    So to answer my original question the following commands need to be run after downloading the rerere-train.sh script to the parent directory:

    git config rerere.enabled true
    ../rerere-train.sh H
    git checkout H
    git rebase --rebase-merges C
    git commit -a
    # Here you save the commit message of the merge
    git rebase --continue
    

    For more merges in the rebased branch rerere-train.sh can be used before the rebase for each merge.