Skip to content

Use 3-way merge for squashing commits

Stan Hu requested to merge sh-use-3way-merge-for-squash into master

A high number of squashes fail because some lines in the target branch changed in another commit. However, this failure doesn't happen if you attempt to squash a branch and merge it in this way:

  1. git checkout my-branch
  2. git rebase -i HEAD~N (where N is some number of commits)
  3. git checkout master
  4. git merge my-branch

The fourth step does a 3-way merge by default. From https://git-scm.com/docs/merge-strategies#_merge_strategies under recursive:

This can only resolve two heads using a 3-way merge algorithm...This is the default merge strategy when pulling or merging one branch.

To emulate this behavior, we add --3way to the parameters when we attempt to apply the patch onto the target branch.

Part of https://gitlab.com/gitlab-org/gitlab-ee/issues/10661

Edited by GitLab Release Tools Bot

Merge request reports