This question and some others discuss how this could work on a Mac, but I couldn't find documentation from Microsoft or Atlassian on a way to do this on Windows without trying to make it the global Git setting. (I just prefer to change things within the IDE where possible.)
What are the parameters to use with the "Custom" settings in SourceTree's "Options" dialogue "Diff" tab, for diff'ing and merging with VS-Code?
SourceTree config First, open up the options window and go to Diff tab. Change both External Diff Tool and Merge Tool to Custom. In the Diff Command field enter the full path to the vsdiffmerge.exe. For VS 2015 and below you can find it in the Visual Studio installation folder, under Common7\IDE subfolder.
Diffing in VS Code is very useful for quickly seeing changes between two files. It also helps to remind yourself of the changes you've made from the master version of a file on git once in a while. VSCode diffs are a great thing to add to your developer toolbox.
There may be other better variations, but after some experiment I've found these work well enough...
C:\Program Files (x86)\Microsoft VS Code\Code.exe
The command-line arguments for Diff'ing are:
--diff --wait "$LOCAL" "$REMOTE"
And for Merging:
-n --wait "$MERGED"
The '-n' flag makes VS-Code open a new window, which I prefer since VS-Code opens so fast, but you can omit it. When dealing with merge conflicts, you have to close the file when you're done to continue. SourceTree doesn't seem to consistently delete the intermediate files it creates, but you can select, right-click and 'Remove' them from the un-staged file section easily enough.
I was able to set up with the following steps using the code.cmd
script:
code.cmd
command
C:\Users\[username]\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
Using the same command-line arguments as @HeyHeyJC explains
The command-line arguments for Diff'ing are:
--diff --wait "$LOCAL" "$REMOTE"
And for Merging:
-n --wait "$MERGED"
For me I was then able to use both diff and merge from Sourcetree.
Note: By default the code.cmd
file contained a command line argument to open the CLI instructions "%~dp0..\resources\app\out\cli.js"
, and having this open each time was a bit tedious! I removed this so my file looked as follows, and now only the files sent from Sourcetree are opened.
@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
call "%~dp0..\Code.exe" %*
endlocal
You need to do below configuration in Sourcetree
Go to Sourcetree → Tools → Options → Diff
In the section External Diff / Merge, select Custom for the External Diff Tool and Merge Tool
Diff Arguments →
--diff --wait "$LOCAL" "$REMOTE"
Merge Arguments → -n --wait "$MERGED"
After configuration is saved, then goto the Sourcetree and right click on the file with merge conflicts Resolve Conflicts → Launch External Merge Tool
Note: Diff and Merge command should point to
C:\Users\<user name>\AppData\Local\Programs\Microsoft VS Code\Code.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With