Last Updated: March 16, 2021
·
28.6K
· peterflynn

Use IntelliJ or WebStorm as your git diff tool (even on Windows)

JetBrains's IntelliJ IDEA (and related IDEs like WebStorm) include a diff/merge tool that is just awesome. Here's how to use it with Git:

Mac

Open ~./.gitconfig and add:

[merge]
    tool = intellij
[mergetool "intellij"]
    cmd = /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
    trustExitCode = true
[diff]
    tool = intellij
[difftool "intellij"]
    cmd = /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea diff $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")
</code></pre>

Windows

Open c:\Users\<username>\.gitconfig and add:

[merge]
    tool = intellij
[mergetool "intellij"]
    cmd = cmd.exe //c "\"C:/Program Files (x86)/IntelliJ IDEA Community Edition 12.0/bin/idea.bat\" merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
    trustExitCode = true
[diff]
    tool = intellij
[difftool "intellij"]
    cmd = cmd.exe //c "\"C:/Program Files (x86)/IntelliJ IDEA Community Edition 12.0/bin/idea.bat\" diff \"$LOCAL\" \"$REMOTE\""
</code></pre>

Be sure to adjust the path as needed for your version of IntelliJ, WebStorm, PHPStorm, etc.  I believe this works in IntelliJ >= 10.5 (or similar vintage of the other tools), but I've only actually tested it with IntelliJ 12.

Once you're set up, just use git difftool or git mergetool to invoke your sweet new diff UI!

5 Responses
Add your response

I get:
$ git difftool
fatal: bad config file line 69 in c:/Users/eturley/.gitconfig

Line 69 is:
cmd = cmd.exe //c "\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1.4\bin\idea.bat\" merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""

So I try to check it by running this in git bash:
$ cmd.exe //c "\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1.4\bin\idea.bat\" diff DmfsException.java DmfsException1.java"
'\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1.4\bin\idea.bat\"' is not recognized as an internal or external command, operable program or batch file.

It all seems to look right for me - yet doesn't work. Any suggestions?

ANSWER:
Turns out I had to change mine to reference "idea.exe" instead of "idea.bat".

over 1 year ago ·

I don't know for windows but on Mac to make it work I had to double escape white space in executable path like follow :

[mergetool "intellij"]
cmd = /Applications/IntelliJ\\ IDEA\\ 13\\ CE.app/Contents/MacOS/idea merge $(cd $(dirname \"$LOCAL\") && pwd)/$(basename \"$LOCAL\") $(cd $(dirname \"$REMOTE\") && pwd)/$(basename \"$REMOTE\") $(cd $(dirname \"$BASE\") && pwd)/$(basename \"$BASE\") $(cd $(dirname \"$MERGED\") && pwd)/$(basename \"$MERGED\")

It seems due to the textfields on this website. "\" escape next character as well so I had to tripple them myself to display two \\ .

if you still have issues maybe just use the command line syntax (here for mac again)

# use intellij as your merge tool
git config --global mergetool.intellij.cmd '/Applications/IntelliJ\ IDEA\ 13\ CE.app/Contents/MacOS/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")'
git config --global mergetool.intellij.trustExitCode false
git config --global merge.tool intellij

# then call "git mergetool -y"

over 1 year ago ·

I have a similar setup and wonder whether you have any recommendations to speed up launch time. Right now I'm very tempted to switch back to Kdiff3 because it takes so long to launch IntelliJ for every file.

over 1 year ago ·

@milgner SSD is a good investment! I got a Samsung 850 Pro 1TB SSD, 32 GB RAM and an i7 CPU. Webstorm takes about 3.5 seconds.

over 1 year ago ·

thank you so much! This is really awesome!!!

over 1 year ago ·