A bug in the IntelliJ IDEA merge conflict was recorded (the merge fails when the code is the same as the local repository after the conflict is resolved)

Hits: 0

Table of contents

IntelliJ IDEA version

IntelliJ IDEA 2017.1.4 x64

  • 1

Problem Description

We often encounter conflicts when developing with git. It usually occurs in collaborative development, and a file is changed by two people at the same time. This is when we pull the code to resolve the conflict, and re-add and then [commit] and finally push.

This blog records a small problem in resolving conflicts in IntelliJ IDEA. Let’s construct the conflict first

github is as follows:

The local IDEA is as follows:

The data in the third line of README.md in the local warehouse and github is different. If we push, it will prompt us that we need to pull (fetch+merge) first. This prompt will not be demonstrated here. We will pull directly.

Prompt us that there is a conflict, we choose merge and resolve the conflict on IDEA

Note the image below:

We resolve the conflict as follows: Then click apply

After resolving the conflict, we need to re-add, commit and then push, but at this time, when we checked the current status with the git status -s command through the windows git bash client, we found that there was no code that could be added. However, at the end of the arrow position ( master|MERGING)
Note: This MERGING appears at the beginning of the merge and disappears at the completion of the commit, that is, the merge ends.
git bash (pure command line) / linux (centos) pure command line: even if the conflict resolution code is the same as the local warehouse code We take the add commit. Before adding, we will find that the front status of this file is UU IDEA to handle the conflict: If the code that finally resolves the conflict is different from the local warehouse code, here will be a prompt that there is content that can be added. (status -s view status is UU in front of the file, the same as git bash / linux), and the code that resolves the conflict if the local warehouse code is the same, as shown in the figure below. At this time, the git diff and git diff –cached commands are used to view the discovery The working area, staging area, and local warehouse code are all the same.

Because we can’t add the above, so we commit directly through IDEA. It actually prompts us that there is no code that can be committed.

Let’s take a look at the git log. Obviously, the merge has not been completed yet. Obviously I have resolved the conflict just now, but IDEA is halfway through the merge.

If we try to push the code to the warehouse at this time, this will happen: (to the effect that the merge needs to be pushed first, that is, half of the merge is now)

At this time, if we try to merge through IDEA’s own git, there will be an error, because there is a merge now in progress. As shown below


Now that the problem is located, IDEA has a problem in the middle of the merge. So the next thing can only be solved by ourselves. Let’s analyze where the break is now, because I just checked it through the git diff and git diff –cached commands No difference was found in the state, so let’s assume that add has been completed. Well, we can commit ourselves through the command line

The following commit information (generated by merge) appears, :wq exits, and the merge succeeds.

Observing IDEA’s git log found that it is also normal

There is another solution: we directly delete .git/MERGE_HEAD, so that the merge in the middle of the process will be killed by us. I have not tried this method, and interested students can try it

Leave a Reply

Your email address will not be published.