The merge tool that ships with JetBrain's IntelliJ IDEA or WebStorm is really awesome and way better than FileMerge
. It is quite simple to configure SourceTree to use it as the default mergetool:
-
Open the SourceTree preferences and select the
Diff
tab -
Choose
Custom
both asVisual Diff Tool
and asMerge Tool
-
Paste the following commands into the textfields:
-
Diff Command:
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea diff
- Arguments:
$(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")
- Arguments:
-
Merge Command:
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea merge
- Arguments:
$(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
- Arguments:
-
-
Close the settings. Happy merging!
To manually change the mergetool for git in general follow these steps:
-
Open the
~/.gitconfig
file with your favorite editor -
Add these lines somewhere in the config:
[merge] 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\") [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
It takes a few more seconds to launch the IntelliJ merge tool than to launch FileMerge, but it is definitely worth waiting.
Based on this article on coderwall: https://coderwall.com/p/gc_hqw/use-intellij-or-webstorm-as-your-git-diff-tool-even-on-windows
I recently updated from RubyMine some 2020 version to 2021.3.2. It started running into an error, saying it couldn't find the file. I tried the wait option, which didn't work. I also tried manually adding a sleep statement, like
cmd = sleep 5 && mine merge ....
but that didn't work either.Ultimately I had to change
trustExitCode = true
totrustExitCode = false
, and that causes Rubymine to successfully open the merge window. This requires typing "y" after each file though.Before I was using this long command:
but now it's working with just