Skip to main content

Resolving Merge Conflicts

Merge conflicts or code collisions sometimes occur as a normal part of the merge request workflow. However, they can be annoying for developers, especially when working on larger projects and in larger teams, where the chance of code collisions are increased. However, techniques exist to avoid encountering merge conflicts in the first place, and DataOps provides functionality for the online resolution of conflicts that do happen.

Avoiding merge conflicts

To reduce the chance of code conflicts affecting your merge requests, we recommend following the below tips, techniques, and best practices in your DataOps projects:

  • Structure code in multiple, smaller files rather than large ones.
  • Keep merge requests small and specific, minimizing code changes to a particular change.
  • Merge as soon as possible, with regular review/approval cycles to avoid delays.
  • Avoid non-standard code beautifiers that reformat whole files.
  • Refresh your feature branch regularly if work spans multiple days.
  • Ensure good communication within teams to understand potential code overlaps better.

Resolving merge conflicts in DataOps.live

When raising and reviewing merge requests in DataOps.live, developers and maintainers should see the following view - a safely-mergeable branch:

no-conflict-mr !!shadow!!

However, if there is a conflict in a file, usually caused by code changes that abut or overlap, the merge section looks like this:

merge-conflict-resolvable !!shadow!!

The DataOps.live IDE provides a mechanism to click through, review the conflicting content, and resolve it to solve this merge conflict. Once the conflict has been resolved, the developer or maintainer can commit changes by clicking the Resolve conflicts button:

resolve-conflicts !!shadow!!

note

There can be more than one merge conflict in a feature branch.

You can select the correct change(s) from this view and commit back to the source branch. The merge will then be able to go ahead successfully.

However, some changes, particularly involving the renaming or deletion of files, will not be resolvable in the data product platform:

merge-conflict-unresolvable !!shadow!!

In these scenarios, the developer should clone the project locally and rebase against the target branch, resolving any conflicts by hand. The developer can then push the updated branch back to the merge request, which should then become mergeable.

Resolving merge conflicts in merge requests

The intended workflow for merge requests is from a feature branch to a dev branch. As part of that workflow, you regularly need to resolve merge conflicts against the target branch before being able to perform the merge. The UI guides you through that process such that the conflict gets resolved in the feature branch.

warning

Resolving merge conflicts in the Merge Request web interface reverses the commit direction you expect from a git merge command. Changes will be applied to the source branch, where the source branch is the branch you are merging from.

Therefore, do NOT use the web interface to merge from a dev branch to a feature branch if you have merge conflicts. Resolved merge conflicts would get committed to the dev branch and not, as you might expect, the feature branch.

To resolve the merge conflicts, use alternatives such as the Git command line git merge or git rebase, visual merge tools like Visual Studio Code, etc.