IntelliJ IDEA 2016.3 Help

Resolving Conflicts

Depending on your version control system, conflicts may arise in different situations.

When you work in a team, you may come across a situation when somebody commits changes to a file you are currently working on. If these changes do not overlap (i.e. changes were made to different lines of code), the conflicting files are merged automatically. However, if the same lines were affected, your version control system cannot randomly pick one side over the other, and asks you to resolve the conflict.

Conflicts may also arise when merging, rebasing or cherry-picking branches.

In this topic:

Non-Distributed Version Control Systems

When you try to edit a file that has a newer version on the server, IntelliJ IDEA informs you about that, showing a message pop-up window in the editor:

In this case, you should update your local version before changing the file, or merge changes later.

If you attempt to commit a file that has a newer repository version, the commit fails, and an error is displayed in the bottom right corner telling you that the file you are trying to commit is out of date.

If you synchronize a file that already has local changes with a newer repository version committed by somebody else, a conflict occurs. The conflicting file gets the Merged with conflicts status. The file remains in the same changelist in the Local Changes tab of the Version Control tool window, but its name is highlighted in red. If the file is currently opened in the editor, the file name on the tab header is also highlighted in red.


Distributed Version Control Systems

Under distributed version control systems, such as Git and Mercurial, conflicts arise when a file you have committed locally has changes to the same lines of code as the latest upstream version and when you attempt to perform one of the following operations: pull, merge, rebase, cherry-pick, unstash, or apply patch.

If there are conflicts, these operations will fail and you will be prompted to accept the upstream version, prefer your version, or merge the changes manually:


Conflict Resolution Tool

IntelliJ IDEA provides a tool for resolving conflicts locally. This tool consists of three panes. The left pane shows the read-only local copy; the right pane shows the read-only version checked in to the repository. The central pane shows a fully-functional editor with the results of merging and conflict resolving are displayed. Initially, the contents of this pane is the same as the base revision of the file, that is, the revision from which both conflicting versions are derived.

To resolve conflicts, do the following:

  1. Click Merge in the Files Merged with Conflicts dialog, or select the conflicting file in the editor and choose VCS | <your_VCS> | Resolve Conflicts from the main menu.
  2. To automatically merge all non-conflicting changes, click /help/img/idea/2016.3/applyNotConflicts.png (Apply All Non-Conflicting Changes) on the toolbar. You can also use the /help/img/idea/2016.3/applyNotConflictsLeft.png (Apply Non-Conflicting Changes from the Left) and /help/img/idea/2016.3/applyNotConflictsRight.png (Apply Non-Conflicting Changes from the Right) to merge non-conflicting changes from the left/right parts of the dialog respectively.
  3. To resolve conflicts, select the change to be merged in the left or right pane. Use the chevron (/help/img/idea/2016.3/chevron_button.png) or the /help/img/idea/2016.3/ignore_button.png buttons to apply or discard the selected change:

    For simple conflicts (for example, if the beginning and the end of the same line have been modified in different file revisions), the Resolve option is available that allows merging the changes in one click:

  4. Review merge results in the central pane and click Apply.

See Also

Last modified: 21 March 2017