Please help to understand how git merge works in IDEA.

Answered

I have GIT merge conflict flagged in IDEA, and I merging develop branch into my Rental_Return branch. I see the branches code on left and right and it seems good.

Right side is empty as file was not in develop branch. How conflict happen then? I expect no conflict in this case.

Also I cannot get the code in the middle window - named "result". It contains some code which is not on left or right sides of merge window. Where is this code comes from? I could think it

PS I not edited code shown on screenshot manually. It is all what I see once after I clicked Merge.

9 comments
Comment actions Permalink

PM

Could you please clarify whether you have moved a file on one of your branches? It seems that you have faced an issue:
https://youtrack.jetbrains.com/issue/IDEA-267443

As for a piece of code:
The middle panel displays code that corresponds to a revision of  `git merge-base develop feature/Rental_Return`

0
Comment actions Permalink

I found this class was removed on develop branch few commits ago, so may be you right. The unexpected code in a middle comes from removed file. I would say this is a bug. Is it?

0
Comment actions Permalink

But I see same happen when merging file was not removed. The code in a middle not coming from any of two branches. Here from same merge but different file:

0
Comment actions Permalink

PM
The middle panel shows you the closest ancestor to both of these branches, so it's a version that has been in both branches.

0
Comment actions Permalink

I get what you saying. But I not understand why is it so. When I merge I expect to see code from latest commits of branches I merge, but not from closest common to both branches ancestor. This way I can choose which version to take (left or right). Now it seems like middle pane shows third status.

 

Is this middle panel behavior following git merge protocol, or it is something Intellij IDEA team decided to do?

0
Comment actions Permalink

The central panel helps to show what changes the branches introduced. It allows not only to compare two states but also to see what was changed in the branches to better understand the change, and merge them.

The central pane is diffed against both left and right sides. Those chunks that are modified on both sides are in fact conflicts.

It is a git concept, git uses this content to calculate the diff. Just git itself does not show the base in the editor.

The contents for all 3 panes is retrieved from git using

git cat-file -p --filters :1:/path/to/conflcting/file - for the central pane
git cat-file -p --filters :2:/path/to/conflcting/file - for the left one
git cat-file -p --filters :3:/path/to/conflcting/file - for the right one

See https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltngtltpathgtemegem0READMEememREADMEem

0
Comment actions Permalink

Thanks for clarification.

However I not see described central panel behavior helpful for me. Thing is I would prefer to resolve merge conflict in a way similar to classic git merge. This involves only two statuses:

<<<<<<< branch-a
text changed here
=======
here it changed as well
>>>>>>> branch-b

the central panel with common parent status is a third status, which seems not brings any benefit and confusing.

Is there an option, to have status of the current branch in central panel when merge starts?

Or other option could be to see merge conflict data from both branches in one window. Same as git merge do:

<<<<<<< branch-a
...
=======
...
>>>>>>> branch-b
0
Comment actions Permalink

> Thing is I would prefer to resolve merge conflict in a way similar to classic git merge

You can do it directly in the editor, in the classic git way.

IDE could better support this scenario and this is something we consider - please vote/follow https://youtrack.jetbrains.com/issue/IDEA-140959

 

> Is there an option, to have status of the current branch in central panel when merge starts?

It would be identical to one of the sides, so there is no need for a 3 panel in this case at all.

But we believe seeing the base revision makes it easier to understand the changes and make a better-informed decision. There is no option to change that, and there are no plans to add one currently.

However, from the 3-panel merge dialog, you can open diff between 2 selected revisions, using the button on the toolbar. Comparing Left and Right will likely show what you want.

 

 

0
Comment actions Permalink

I tried this:

However, from the 3-panel merge dialog, you can open diff between 2 selected revisions, using the button on the toolbar. Comparing Left and Right will likely show what you want.

and got modal window (on top of merge modal window). There is no way to merge in it - left and right panels not editable. So this is not a solution:

Thanks for your time, though. Now I see how this works.

PS modals can bring bad user experience. If I have few projects open on few screens and one of them shows modal - all other projects blocked by this modal, besides IDEA IDE covers all other apps (like browser, text editor etc)

0

Please sign in to leave a comment.