Search code examples
pythonpycharmmerge-conflict-resolution

How do I view code while resolving merge conflicts in PyCharm


Say I have a repo with 2 files:


source.py

def foo() -> int:
    return 1

conflict.py

from source import foo

def bar() -> int:
    return foo()

Now, I create and try to resolve a merge conflict:


conflict.py

from source import foo

def bar() -> float:
    return foo()

I get the expected dialog box and am able to resolve the conflict:

Resolve merge conflict


Now how do I review the code and check the actual return type of foo()?

The merge conflict resolve window is fixed on top. Command/ctrl+clicking foo() does not work. Even opening a second clone of my repo doesn't escape this intrusive behaviour.

This behaviour is the same for macOS and Windows. I'm using PyCharm 2022.2.3 Professional.


Solution

  • There's a workaround - confirmed for version 2022.3 Professional and 2023.3 Professional.

    Quoting Dirk Moebius on the thread linked by Dino Letic:

    I just found out there's a way to circumvent the modal dialog entirely, but it's not obvious:

    When the "Conflict" dialog opens during a merge, don't press "Merge", press the "Close" button instead. Then the merge conflicts will show up in a section called "Merge conflicts" in the "Commit" tab.

    The "Merge conflicts" section has a link "Resolve...", but don't click this, it only opens the same modal dialog again. Instead, for each conflicting file, right click on it and select "Merge..." from the context popup menu. This will open the Merge dialog again, but this time it's only for the selected file, and it's not modal! You can switch back to the main IDE window and inspect and edit other files there. You can move the Merge dialog on a second monitor and work on both windows at the same time!

    After you solved all conflicts in that Merge dialog for this file, either click on "Apply", or click on the link "Save changes and finish merging" in the popup that appears. Both actions just resolve the conflict for the current file. (The text "... and finish merging" is misleading here, because it does not actually finish the merging as long as there are other conflicts.)

    Repeat these steps for each file until all conflicts are resolved.

    I used IntelliJ IDEA 2021.2.3 Enterprise Edition. Don't know if other versions support this kind of workflow.


    Step 1 (Optional)

    Close the conflict resolve prompt you get after pulling.

    Conflict prompt


    Step 2

    Right click the file you want to resolve instead and select Merge. Do not try to resolve by selecting the blue Resolve text This opens the previous prompt which leads to the problematic modal. Instead resolve files separately.

    Conflict menu

    Conflict dropdown


    Step 3

    Now you can resolve your conflict while reviewing your code.