Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 898
Ondra Žižka Avatar asked Jan 29 '23 04:01

Ondra Žižka


2 Answers

You could call IDEA as a merge tool - /usr/local/bin/idea merge <local> <remote> [base] <merged>. More information at https://www.jetbrains.com/help/idea/running-intellij-idea-as-a-diff-or-merge-command-line-tool.html

There is no way IDEA could find all conflicts on its own, but you could configure it as the default merge tool for git, as proposed by Carlo. This should work

like image 162
Dmitriy Smirnov Avatar answered Feb 05 '23 14:02

Dmitriy Smirnov


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.

like image 33
Carlo Bellettini Avatar answered Feb 05 '23 14:02

Carlo Bellettini