Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use PHPStorm/WebStorm for git diff and merge tools
# ~/.gitconfig
# Add this to your global git configuration file
# Change phpstorm to webstorm, if you use that.
# Diff and merge tool changes
# Run `git difftool <directory/file>...` or `git mergetool <directory/file>...`
[merge]
tool = phpstorm
[diff]
tool = phpstorm
[difftool]
; This setting is optional, but prevents an annoying prompt between diffing files.
prompt = false
[difftool "phpstorm"]
; Putting this path here doesn't work. I would love to know why.
; path = /Applications/PHPStorm.app/Contents/MacOS
cmd = webide diff $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")
trustExitCode = true
[mergetool "phpstorm"]
cmd = webide 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
# Add this to your .profile, .zshrc, .bashrc, etc.
# Add PHPStorm's bin directory to your path.
export PATH="/Applications/PHPStorm.app/Contents/MacOS:$PATH"
@inf3rno

This comment has been minimized.

Show comment
Hide comment
@inf3rno

inf3rno Mar 23, 2013

I don't understand, you can merge and commit from the phpstorm menu... Why would you use something else, and after that change to phpstorm as merge tool?!

inf3rno commented Mar 23, 2013

I don't understand, you can merge and commit from the phpstorm menu... Why would you use something else, and after that change to phpstorm as merge tool?!

@bobbyroberts99

This comment has been minimized.

Show comment
Hide comment
@bobbyroberts99

bobbyroberts99 Jan 30, 2014

Thanks so much for this! Makes using webstorm with git even better. So much easier.

bobbyroberts99 commented Jan 30, 2014

Thanks so much for this! Makes using webstorm with git even better. So much easier.

@frickenate

This comment has been minimized.

Show comment
Hide comment
@frickenate

frickenate Nov 20, 2014

Thank you for putting me on the right path. This also works on Windows if the git commands for diffing and merging are executed within Git Bash (the sub-shells and pwd calls work fine under cygwin). My config, using the 64 bit PhpStorm binary as the diff and merge tools with SourceTree:

[merge]
    tool = sourcetree
[diff]
    tool = sourcetree   
[difftool]
    prompt = false
[difftool "sourcetree"]
    cmd = 'C:/Program Files (x86)/JetBrains/PhpStorm 8.0.1/bin/PhpStorm64.exe' diff $(cd $(dirname $LOCAL) && pwd)/$(basename $LOCAL) $(cd $(dirname $REMOTE) && pwd)/$(basename $REMOTE)
    trustExitCode = true
[mergetool "sourcetree"]
    cmd = 'C:/Program Files (x86)/JetBrains/PhpStorm 8.0.1/bin/PhpStorm64.exe' 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

frickenate commented Nov 20, 2014

Thank you for putting me on the right path. This also works on Windows if the git commands for diffing and merging are executed within Git Bash (the sub-shells and pwd calls work fine under cygwin). My config, using the 64 bit PhpStorm binary as the diff and merge tools with SourceTree:

[merge]
    tool = sourcetree
[diff]
    tool = sourcetree   
[difftool]
    prompt = false
[difftool "sourcetree"]
    cmd = 'C:/Program Files (x86)/JetBrains/PhpStorm 8.0.1/bin/PhpStorm64.exe' diff $(cd $(dirname $LOCAL) && pwd)/$(basename $LOCAL) $(cd $(dirname $REMOTE) && pwd)/$(basename $REMOTE)
    trustExitCode = true
[mergetool "sourcetree"]
    cmd = 'C:/Program Files (x86)/JetBrains/PhpStorm 8.0.1/bin/PhpStorm64.exe' 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
@JohnAlbin

This comment has been minimized.

Show comment
Hide comment
@JohnAlbin

JohnAlbin Apr 21, 2015

You don't need all of that $(blah blah) any more. Newer versions of PHPStorm and WebStorm have a command line tool, called pstorm or wstorm. So the git config is just:

[diff]
  tool = pstorm
[difftool]
  prompt = false
[difftool.pstorm]
  cmd = /usr/local/bin/pstorm diff "$LOCAL" "$REMOTE"
[merge]
  tool = pstorm
[mergetool.pstorm]
  cmd = /usr/local/bin/pstorm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Or:

[diff]
  tool = wstorm
[difftool]
  prompt = false
[difftool.wstorm]
  cmd = /usr/local/bin/wstorm diff "$LOCAL" "$REMOTE"
[merge]
  tool = wstorm
[mergetool.wstorm]
  cmd = /usr/local/bin/wstorm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

JohnAlbin commented Apr 21, 2015

You don't need all of that $(blah blah) any more. Newer versions of PHPStorm and WebStorm have a command line tool, called pstorm or wstorm. So the git config is just:

[diff]
  tool = pstorm
[difftool]
  prompt = false
[difftool.pstorm]
  cmd = /usr/local/bin/pstorm diff "$LOCAL" "$REMOTE"
[merge]
  tool = pstorm
[mergetool.pstorm]
  cmd = /usr/local/bin/pstorm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Or:

[diff]
  tool = wstorm
[difftool]
  prompt = false
[difftool.wstorm]
  cmd = /usr/local/bin/wstorm diff "$LOCAL" "$REMOTE"
[merge]
  tool = wstorm
[mergetool.wstorm]
  cmd = /usr/local/bin/wstorm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
@ezdata

This comment has been minimized.

Show comment
Hide comment
@ezdata

ezdata May 16, 2015

John. Thank you for your comment. I'm a PHPStorm user. I popped the parameters into .gitconfig and, voila, worked like a charm.

For anyone interested, I used the following command to invoke PHPStorm so I could compare a file across two branches.
git difftool <branch1> <branch2> -- <path/filename>

And for those who need to see a more concrete example:
git difftool new-feature origin/master -- js/broadcast.js

ezdata commented May 16, 2015

John. Thank you for your comment. I'm a PHPStorm user. I popped the parameters into .gitconfig and, voila, worked like a charm.

For anyone interested, I used the following command to invoke PHPStorm so I could compare a file across two branches.
git difftool <branch1> <branch2> -- <path/filename>

And for those who need to see a more concrete example:
git difftool new-feature origin/master -- js/broadcast.js

@shirazd

This comment has been minimized.

Show comment
Hide comment
@shirazd

shirazd Mar 29, 2016

Does anyone know how to configure phpstorm's diff or merge tool to launch in the foreground when issuing a git difftool or git mergetool? I find the background launch inconvenient.

shirazd commented Mar 29, 2016

Does anyone know how to configure phpstorm's diff or merge tool to launch in the foreground when issuing a git difftool or git mergetool? I find the background launch inconvenient.

@Raffaello

This comment has been minimized.

Show comment
Hide comment
@Raffaello

Raffaello Jun 3, 2016

great!

but it doesn't show me any output to me, neither error.

does it conflict with other open PHPStorm istances?
Well, i was expected that a window will pop up to resolve the conflicts, independtly. But nothing shows up and git ask me if the conflict was resolved.

Raffaello commented Jun 3, 2016

great!

but it doesn't show me any output to me, neither error.

does it conflict with other open PHPStorm istances?
Well, i was expected that a window will pop up to resolve the conflicts, independtly. But nothing shows up and git ask me if the conflict was resolved.

@daveferrara1

This comment has been minimized.

Show comment
Hide comment
@daveferrara1

daveferrara1 Jul 28, 2016

Stopped working for me all the sudden. Now "git mergetool /somefile/..." gives me "No IDE instance has been found. New one will be started."

Like @raffaelo I used to have a mergetool gui pop up so I could visually merge what I wanted was best tool around.

daveferrara1 commented Jul 28, 2016

Stopped working for me all the sudden. Now "git mergetool /somefile/..." gives me "No IDE instance has been found. New one will be started."

Like @raffaelo I used to have a mergetool gui pop up so I could visually merge what I wanted was best tool around.

@daveferrara1

This comment has been minimized.

Show comment
Hide comment
@daveferrara1

daveferrara1 Jul 28, 2016

JetBrains support supplied this to fix it: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program

Verified working: PhpStorm-EAP-162.1447.5.dmg

daveferrara1 commented Jul 28, 2016

JetBrains support supplied this to fix it: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program

Verified working: PhpStorm-EAP-162.1447.5.dmg

@thoma5B

This comment has been minimized.

Show comment
Hide comment
@thoma5B

thoma5B Aug 12, 2016

None of the solution worked for me Webstorm 2016.2, unless I set
prompt = true
Then even the handy solution of JohnAlbin works.

If prompt = false, only the first file in the list is opened correctly, then all the other files are not found, prompting:
Error showing diff: Can't find file /tmp/Us1QSf_myfile.js

thoma5B commented Aug 12, 2016

None of the solution worked for me Webstorm 2016.2, unless I set
prompt = true
Then even the handy solution of JohnAlbin works.

If prompt = false, only the first file in the list is opened correctly, then all the other files are not found, prompting:
Error showing diff: Can't find file /tmp/Us1QSf_myfile.js

@zacbraddy

This comment has been minimized.

Show comment
Hide comment
@zacbraddy

zacbraddy Aug 26, 2016

@thoma5B You just saved me some headaches with that prompt, thanks mate.

zacbraddy commented Aug 26, 2016

@thoma5B You just saved me some headaches with that prompt, thanks mate.

@clinyong

This comment has been minimized.

Show comment
Hide comment
@clinyong

clinyong Nov 10, 2016

If you can not find wstorm, open WebStorm, and go to Tools in menu bar then click Command-line Laucher. My WebStorm version is 2016.2.3.

BTW, I can directly use the solution of @JohnAlbin. Thanks.

clinyong commented Nov 10, 2016

If you can not find wstorm, open WebStorm, and go to Tools in menu bar then click Command-line Laucher. My WebStorm version is 2016.2.3.

BTW, I can directly use the solution of @JohnAlbin. Thanks.

@zored

This comment has been minimized.

Show comment
Hide comment
@zored

zored Jan 30, 2018

  • You can also configure it with commands like git config --global mergetool.pstorm.trustExitCode true.
  • You can use difftool --dir-diff, but currently tmp-files may be instantly removed, so I appended my difftool.pstorm.cmd with ; read and press Enter after diff completion.

zored commented Jan 30, 2018

  • You can also configure it with commands like git config --global mergetool.pstorm.trustExitCode true.
  • You can use difftool --dir-diff, but currently tmp-files may be instantly removed, so I appended my difftool.pstorm.cmd with ; read and press Enter after diff completion.
@UrGuardian4ngel

This comment has been minimized.

Show comment
Hide comment
@UrGuardian4ngel

UrGuardian4ngel Feb 4, 2018

FYI: @zored I had to use && read instead on my system, in order for it to not delete the files before I'm done with them.
But that way, it works (for me too). Great work around, though! 👍 😉

P.S.: adding an additional --symlinks flag to the difftool --dir-diff is also a nice "upgrade"...

UrGuardian4ngel commented Feb 4, 2018

FYI: @zored I had to use && read instead on my system, in order for it to not delete the files before I'm done with them.
But that way, it works (for me too). Great work around, though! 👍 😉

P.S.: adding an additional --symlinks flag to the difftool --dir-diff is also a nice "upgrade"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment