Search code examples
gitgit-rebasegit-merge-conflict

Git interactive rebase - any way to instruct git to resolve conflicts keeping the HEAD version?


Tried variations of git rebase -i -Xours master but still conflicts are shown and I have to resolve them manually. Plus it's not entirely clear what happens with non conflicting changes in the case of a conflicting commit - are those kept ?

Use case: temp rebase some old branches on master to see if there are any such changes in those branches (not in master at all), but keeping the version of the code in master for conflicting changes (horrible, horrible conflicts)

$ git --version
git version 2.6.1.windows.1

Solution

  • git ls-files -u | cut -f2- | uniq | git checkout-index --stdin --stage=all \
    | while read base ours theirs path; do
            git merge-file --ours \
                    -L "$path" -L o/"$path" -L b/"$path" \
                    -- $ours $base $theirs
            mv $ours "$path"
            rm $base $theirs
    done