Understand and Resolve Merge Conflicts

This topic describes what you need to know to understand and resolve the merge conflicts that Git can't automatically resolve.

What are Merge Conflicts?

Merge conflicts happen when Git can't automatically determine how to resolve conflicting code changes between commits from two different branches. You need to manually resolve merge conflicts.

In Git, a merge is when users combine commits from different branches. In most cases Git uses the merge strategy that you specified in the Git pane's Merge to resolve the differences between two commits. But in some cases, such as where users have updated the same line of code differently, Git doesn't know which code change is correct. These situations create merge conflicts that you manually resolve by telling Git which code changes to keep and which to discard.

After you manually resolve the merge conflicts, you can successfully commit the changes to the repository.

About the Merge Editor

Use the Merge editor to locate, understand, and resolve merge conflicts in the selected file. The Merge editor provides the same Git functionality that you can access from the command line Git interface.

Git Merge Editor

Each Merge editor feature and how you can use it is explained here:

  • Merge Tab

    The Merge tab displays a drop down list of the branches you're working with and the merge strategy Git uses to resolve most merge conflicts. See Change Git's Merge Strategy. A semantic model is comprised of many SMM files, and any merge conflicts that Git can't resolve are listed by file name in the Merge Conflicts pane.

    You can use the Merge tab to cancel all of the merge conflicts that Git couldn't resolve. See Cancel All Merge Conflicts.


    Merge Tab

  • Branch Panes

    The Branch panes highlight the conflicts between Branch A and Branch B.

    • Branch A - This area highlights the conflicting code from the source (Theirs) branch, which is the branch you're merging from.
    • Branch B - This area highlights the conflicting code from the target (Ours) branch, which is the branch you're merging into.

    Scroll in either pane to locate and review the highlighted conflicts and decide how to resolve them. You can click the branch's Take All button and then go to the Output pane and click Resolve All to use the branch as the source of truth to resolve all conflicts. See the "Output Pane" section below for more information about the Resolve All button.


    Branch Panes

  • Output Pane

    The Output pane stacks and highlights the conflicting code so that you can compare and select which code to use to resolve the conflict. The highlight colors correspond to branches A (Theirs) and B (Ours) displayed in the Branch panes.

    Use the Conflict up and down buttons to locate and review the highlighted conflicts.

    Output Pane

    This section describes the buttons you use to resolve the merge conflicts.

    • A and B Buttons

      How you deselect and select the A and B toggle buttons depends on how you need to resolve the conflict. You can resolve an individual conflict by selecting A or B, or by re-ordering a code sequence conflict by specifying the sequence (for example, branch B's code should be located before branch A's code). See Understand How to Resolve Conflicts.


      A and B Buttons

    • Resolve Item Button

      Use this button to resolve one conflict at a time. After you use the A or B button to specify how to resolve the highlighted conflict, click Resolve Item to mark the item as resolved. After you click Resolve Item, the Output pane navigates to the next conflict. See Resolve Individual Merge Conflicts.


      Resolve Item

    • Resolve All Button

      You can use this button in the following ways:

      In the Output pane, use the A and B buttons to navigate to and specify a resolution for each conflict, and then click Resolve All to resolve all conflicts.

      In the Branch pane, click the Take All button in the A (Ours) or B (Theirs) Branch pane and then click Resolve All to resolve all conflicts using the branch you chose. See Resolve All Merge Conflicts.


      Resolve All

Understand How to Resolve Conflicts

This topic explains how to use the Merge editor's buttons to resolve a file's merge conflicts one at a time or all at the same time.

See About the Merge Editor.

Resolve an Individual Conflict

In the Output pane, use the A and B buttons to specify how to resolve merge conflicts one at a time.

Confirm that the button corresponding to the branch that you want to use to resolve the conflict is highlighted. By default both A and B are selected, so to select A, you must deselect B.

After you set the A and B buttons to indicate how to resolve the conflict, click the Resolve Item button to resolve the issue and navigate to the next conflict.

Reorder a Code Change to Resolve an Individual Conflict

In the Output pane, use the A and B buttons to reorder a code change to resolve a conflict.

Select a sequence for a conflict where you need to reorder (or stack) a code change. To specify a sequence, click the A button and then the B button to deselect them. Then click the buttons in either the A before B (so A's code before B's code) or B before A (so B's code before A's code) sequence to specify how to stack the changes. Then click the Resolve Item button to resolve the issue and navigate to the next conflict.

Resolve All Conflicts at the Same Time

Note:

You can't use the Resolve All button with the Output pane's A and B buttons to resolve all conflicts at the same time.

In the Branch pane, click the Take All button for the A (Ours) or B (Theirs) branch that you want to use as the single source of truth to resolve all conflicts, and then click Resolve All.

Mark Individual Conflicts and then Resolve All Conflicts as Marked

In the Output pane, use the Conflict up and down buttons to navigate to each highlighted conflict and use the A and B buttons to specify how to resolve each highlighted conflict. After you've specified how to resolve each item, click Resolve All to resolve all conflicts.

Change Git's Merge Strategy

You can choose how you want Git to automatically resolve the merge conflicts that it finds in your branches. In most cases Git can use the merge strategy to resolve the differences between branches.

You can choose from the following Git merge strategies:

Semantic Merge - Use this option to use Semantic Modeler's merge strategy. Semantic Merge merges the model's objects and not just text. Oracle recommends that you use this merge strategy.

Git Merge - Use this option to use Git's default merge strategy. Git's default merge strategy uses a three way algorithm. In cases where there is more than one common ancestor, Git creates a merged tree of the common ancestors and uses it to determine the three way merge.

Ours - Use this option to have Git resolve conflicts by favoring code changes from the branch that you are merging into. This is branch B or the target branch. If you select this option, Git won't use Ours to resolve all merge conflicts, but only when it can't use its default merge strategy to resolve specific conflicts.

Theirs - Use this option to resolve conflicts by favoring code from the branch that you are merging from. This is Branch A or the source branch. If you select this option, Git won't use Theirs to resolve all merge conflicts, but only when it can't use its default merge strategy to resolve specific conflicts.

If Git can't automatically resolve the merge conflicts, then the Merge Conflicts pane is displayed and lists the conflicts that you must resolve manually. See Resolve All Merge Conflicts and Resolve Individual Merge Conflicts.

  1. On the Home page, click Navigator and then click Semantic Models.
  2. In the Semantic Models page, click a semantic model to open it.
  3. Click Toggle Git Panel to open the Git pane.
  4. Click the Merge tab and go to the Strategy field and select a merge strategy to use when you merge branches.
  5. Click Merge.

Cancel All Merge Conflicts

You can cancel the merge process and reconstruct the pre-merge state of the branches.

If your semantic model contained uncommitted changes when you started the merge, then Git might not be able to reconstruct the pre-merge changes.

  1. On the Home page, click Navigator and then click Semantic Models.
  2. In the Semantic Models page, click a semantic model to open it.
  3. Click Toggle Git Panel to open the Git pane.
  4. Click the Merge tab and go to the Merge Conflicts pane.
  5. Click Cancel All.

Resolve All Merge Conflicts

You can choose one branch as the source of truth to resolve all merge conflicts in the selected file.

The Branch panes highlight the conflicts between Branch A and Branch B.

  • Branch A - This pane highlights the conflicting code in the Their branch, which is the source branch or the branch you're merging from.
  • Branch B - This pane highlights the conflicting code in the Ours branch, which is the target branch or the branch you're merging into.

Note:

You can't resolve all conflicts by clicking the Output pane's A or B button and then clicking the Resolve All button.

Resolving merge conflicts doesn't fix inconsistencies in your semantic model. You must run the consistency check to detect and fix inconsistencies in your semantic model.

  1. On the Home page, click Navigator and then click Semantic Models.
  2. In the Semantic Models page, click a semantic model to open it.
  3. Click Toggle Git Panel to open the Git pane.
  4. Click the Merge tab and go to the Merge Conflicts pane.
  5. Right-click a file and select View Conflicts.
  6. In the Branch panes, click the Take All button corresponding to the branch that you want to use to resolve all merge conflicts in the file.
  7. In the Output pane, click Resolve All.
  8. Go to the Merge Conflicts pane and confirm that the file that contained the conflicts was removed from the list.
  9. In the Merge tab, click Merge.

Resolve Individual Merge Conflicts

You can review and resolve each of the selected file's merge conflicts one at a time.

The Output pane displays and highlights the conflicting code side-by-side so that you can compare and select which code to use to resolve the conflict. The highlight colors correspond to branches A (Theirs) and B (Ours) displayed in the Branch panes.

For each conflict, use the A and B buttons to specify which branch's code you want to use to resolve the highlighted conflict. By default both buttons are selected, so to select A, you must deselect B. Or use the A and B buttons to specify the order (or stacking) of the code changes. See Understand How to Resolve Conflicts.

Resolving merge conflicts doesn't fix any inconsistencies in your semantic model. You must run the consistency check to detect and fix inconsistencies in your semantic model.

  1. On the Home page, click Navigator and then click Semantic Models.
  2. In the Semantic Models page, click a semantic model to open it.
  3. Click Toggle Git Panel to open the Git pane.
  4. Click the Merge tab and go to the Merge Conflicts pane.
  5. Right-click a file and select View Conflicts.
  6. In the Output pane, locate the highlighted merge conflict.
  7. Use the A and B buttons to specify how to resolve the conflict. Click Resolve Item.
  8. Click Conflict Navigate Down to highlight the next merge conflict.
  9. Use the A and B buttons to specify how to resolve the conflict. Click Resolve Item.
  10. Navigate to each conflict and resolve it.
  11. After you've resolved all conflicts, go to the Merge Conflicts pane and confirm that the file that contained the conflicts was removed from the list.
  12. In the Merge tab, click Merge.