IntelliJ IDEA - how to trigger Git conflicts resolving from a command line

Viewed 4062

I use git from mostly from a command line, but for conflicts resolving, I prefer an IDE. Specifically IntelliJ IDEA.

Currently I attempt a rebase, and see conflicts. So I need to go to IDEA and click "VCS -> Git -> resolve conflicts". And then go back to console and run git rebase --continue.

I think I can configure git to call a program to handle conflicts.

Is there a way to invoke IDEA's conflicts resolving from a command line? Something like idea --git-resolve-conflicts $(PWD).

Perhaps after installing a right plugin? This is what IDEA gives me as help:

Usage:
  /usr/local/bin/idea -h | -? | --help
  /usr/local/bin/idea [project_dir]
 /usr/local/bin/idea [-l|--line line] [project_dir|--temp-project] file[:line]
  /usr/local/bin/idea diff <left> <right>
  /usr/local/bin/idea merge <local> <remote> [base] <merged>
2 Answers

First thing you have to define the tool to be used for merge resolution in ~/.gitconfig (global) or project/.git/config (just for your project)

[mergetool "idea"]
    cmd = /usr/local/bin/idea merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
    trustExitCode = false
[merge]
    tool = idea

then in a normal session, when after a git merge command some conflict arises, call:

git mergetool

I edited modifying to false the trustExitCode settings... so that it does not fail when multiple conflicting files. After each file in the shell is asked confirmation whether the conflict about the current file is solved and then it proceeds with the next one.

Related