How do I use Meld as a merge tool with Sourcetree on Windows? - atlassian-sourcetree

I have the following in my .gitconfig file:
[user]
name = myname
email = myname#gmail.com
[core]
autocrlf = true
excludesfile = C:\\Users\\myname\\Documents\\gitignore_global.txt
[diff]
tool = meld
[difftool "meld"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
prompt = false
[merge]
tool = meld
[mergetool "meld"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
[difftool "sourcetree"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE"
[mergetool "sourcetree"]
cmd = 'C:/Program Files (x86)/Meld/meld/meld.exe' \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = true
And in Sourcetree, I have the following settings:
However, when I right-clicked a file on Sourcetree to do an external diff, I was able to open Meld, but the contents of the file were not displayed at all.
What have I done wrong in the settings?

I feel the existing answers slightly missed the point. Here is my own dog food:
Arguments Detail:
Diff: $LOCAL $REMOTE
Merge: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
For External Diff, you need to remove $BASE from your argument list.
For 3-way merging, you need to click on the External Merge Tool option instead, which will only be available if there are any unsolved conflicts.
If you are not restricted to Sourcetree + Meld, I reckon the Git Extensions + KDiff3 suite could be a good open-sourced alternative also.

The actual setting to use here in order to have a real 3-way merge, with read only THEIRS and MINE tabs is this:
$LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
Note the = after --output.
I've finally got this command right by digging in comments on the second answer to this question Git merging using Meld.

For OS X it looks like this:
Diff Command: /Applications/Meld.app/Contents/MacOS/meld.
Arguments: $LOCAL $REMOTE
Merge Command: /Applications/Meld.app/Contents/MacOS/meld.
Arguments: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
P.S.
you might have to configure the order of $local and $ remote in meld prefrences as well..
To use it from command line you have to install it via brew:
brew install meld

Try adding the location of meld.exe to your PATH (e.g. C:\Program Files (x86)\Meld), and then in the Diff Command, just enter meld instead of the full path. See the gist How to use meld with Sourcetree on Windows.

If you don't want to modify the PATH environment variable, you can use the DOS-compatible short names:
C:\Progra~1 = C:\Program Files
C:\Progra~2 = C:\Program Files (x86)
That avoids the trouble-causing spaces in the path and plays nice with Sourcetree. It's hackish, but it works. You can then use something like this as the path to Meld:
C:\Progra~1\Meld\meld.exe
It may not be guaranteed that Progra~1 maps to the 64-bit directory, so you might need to experiment with which one maps to which.

Related

Mistake in Mercurial Extdiff Configuration?

I use Mercurial with the Extdiff extensions to diff Simulink (.slx) files with Mathworks' diff tool. To setup the Extdiff extension I followed the instructions on this website. Diffing Simulink (.slx) files works really great.
However (and this not at all great) since I set up the extdiff extension, not only Simulink files are diffed with the Mathworks' tool, but also classical Matlab files (.m).
I don't want that, as the Mathworks' diff tool is a bit limited and Matlab files are (they are pure text files) can be easily diffed with Mercurial's standard diff tool.
Below you find my mercurial.ini. As you can see, it's configured to use extdiff for .slx-files. However there is no setting setting for .m-files.
# Generated by TortoiseHg settings dialog
[tortoisehg]
confirmaddfiles = True
confirmdeletefiles = True
[ui]
username = myname
[extensions]
largefiles =
extdiff =
[extdiff]
# Simulink
slxdiff = matlab -wait -nodesktop -r \"disp(\'Starting visdiff, please wait (even after the prompt appears).\');visdiff(\'$parent\',\'$child\')\"
[diff-patterns]
**.slx = slxdiff
So, the question is:
How do I need to change my configuration to diff .slx files with Mathworks' diff tool and Matlab files with Mercurial's standard diff tool?
Finally I've found a solution. By adding a diff-pattern for m-files I could force kdiff for m-files.
[diff-patterns]
**.slx = slxdiff
**.m = kdiff3
[extdiff]
# Simulink
slxdiff = matlab -wait -nodesktop -r \"disp(\'Starting visdiff, please wait (even after the prompt appears).\');visdiff(\'$parent\',\'$child\')\"
kdiff3.args = $base $local $other -o $output

ssh-keygen: The System Cannot Find the Path Specified

ssh-agent, ssh-add all works on Cmder running PowerShell/Posh-Git
I have added C:\Program Files\Git\usr\bin Environment Variables
ssh-keyen works fine on Git Bash,
how can I make ssh-keygen to also work with Powershell/Posh-Git ?
EDIT:
It turns out that the error is due to the fact that ssh-keygen in PowerShell is running the ssh-keygen.bat file instead of ssh-keygen.exe
So setting an alias as mention below is the way to go.
I use Set-Alias instead of New-Alias because New-Alias requires me to reset my $profile every now and then, which is weird.
To reset, type . $profile
One way to do this is to add it to your path.
Unfortunately, there appears to be no way to add only the executable. In other words, you will be required to add the whole bin folder (namely C:\Program Files\Git\usr\bin) to your path.
I can show you how to add the whole directory to the path, but I don't think this is what you want. Instead, below is an alternative method that only adds the ssh-keygen.exe executable.
Navigate to $env:homepath\Documents\WindowsPowerShell (create it if you don't have it).
Create a file called profile.ps1.
Add to the file the following line of code.
New-Alias Ssh-Keygen "C:\Program Files\Git\usr\bin\ssh-keygen.exe"
Now, each time you launch Powershell, Ssh-Keygen will be available. It even works with tab completion (e.g. type ssh- and press tab, then it automatically becomes Ssh-Keygen).
Actually, you can add single executables from the git bin folder to your path by symlinking them into a folder that is contained in your path variable.
I also wanted to use some of the git tools inside powershell but I didn't want to load the git-bin-folder into path every time I wanted to use one of the tools and I also didn't want to overwrite tools like cp, find, ls and so on...
Create a folder that you can add to path. I created mine in C:\dev\bin and added it to the path variable.
Then you need to symlink all the dll-files from the git bin folder to your new bin folder because the tools you'll link need them in the same directory (the runpath won't be the git-bin-dir but the new bin-dir). I'll add a Script to do that below.
And finally you just need to create symlinks for all tools you'd like to use in powershell as well (hint: ssh.exe is really nice to use in powershell ;))
Here are my powershell functions that'll help you set up your new bin-folder with all the nice tools from git:
# generic symlink function
function Create-Symlink {
param(
[string]$link,
[string]$target
)
& cmd.exe /c mklink "$link" "$target"
}
# symlink all teh git dlls
function Create-GitDllSymlinks {
param(
[string]$newBinDir='C:\dev\bin',
[string]$gitBinDir='C:\Program Files (x86)\Git\bin'
)
$dlls = gci $gitBinDir -Filter *.dll
$dlls | foreach {
Create-Symlink -link (join-path $newBinDir $_.Name) -target $_.FullName
}
}
# to easily link your git tools
function Create-GitSymlink {
param(
[string]$executable,
[string]$newBinDir='C:\dev\bin',
[string]$gitBinDir='C:\Program Files (x86)\Git\bin'
)
if (-not $executable.EndsWith('.exe')) {
$executable = ($executable + '.exe')
}
Create-Symlink -link (join-path $newBinDir $executable) -target (join-path $gitBinDir $executable)
}
# create all dll symlinks needed
Create-GitDllSymlinks
# link ssh and ssh-keygen to use in powershell
Create-GitSymlink -executable ssh-keygen
Create-GitSymlink -executable ssh
Another nice thing to do is this:
create a bash.bat file in your new bin-folder
write this into that .bat file:
"C:\Program Files (x86)\Git\bin\sh.exe" --login -i
quickly switch between powershell and bash:
when in powershell, type bash and git-bash will start inside the same window with access to all git tools in the git-bin-folder.
want to go back to powershell? just type exit!
Edit:
I reinstalled my computer a few days ago (with Win 10) and ran into some issues with my solution above. Apparently, git and/or the cygwin environment in git has been updated and the cygwin applications now search for their unix-environment-paths differently.
For example, ssh always said that it couldn't find my home path:
Could not create directory '/home/myuser/.ssh'.
The authenticity of host 'hostx (IP)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxx.
Are you sure you want to continue connecting (yes/no)?
Using procmon I found out, that it was looking for files in c:\etc and c:\home\myuser. Setting environment variables like HOME or USERPROFILE didn't work, so I just made two additional symlinks to satisfy my cygwin tools:
PS bin # cmd /c mklink /D C:\etc "C:\Program Files\Git\etc"
symbolic link created for C:\etc <<===>> C:\Program Files\Git\etc
PS bin # cmd /c mklink /D C:\home "C:\Users"
symbolic link created for C:\home <<===>> C:\Users
I solved the problem by generating my own ssh key pair using command
$ ssh-keygen -t rsa -C "your_email#mail.com"
in powershell. If you already have a SSH key, then don't a generate new key, as they will be overwritten. You can use ssh-keygen command, only if you have installed Git with Git Bash.
When you run the above command, it will create 2 files in the ~/.ssh directory.
~/.ssh/id_rsa − It is private key or identification key.
~/.ssh/id_rsa.pub − public key
See link generate ssh key

how to alias the current folder

How can I alias the output of this command?
[basename "$PWD"]
I basically want to be able to to do
git browse [basename "$PWD"]
You can run this directly: git browse "$(basename $PWD)"
Or, you could alias it:
alias browsepwd='git browse "$(basename "$PWD")"'
Or, you could write a bash function
function bnpwd() {
basename $PWD
}
Then you can run git browse "$(bnpwd)".
Or any combination of the above ;)
I'm not familiar with git browse, but I suspect what you want is this:
git browse .
Your original concept seems a little flawed to me for this reason - suppose my git repository is in /usr/local/projects/widgets. If I cd /usr/local/projects/widgets, then $PWD will be /usr/local/projects/widgets, and basename $PWD will report widgets. Unless my project has a subdirectory widgets, git browse $(basename $PWD) probably isn't right, and even if such a subdirectory does exist, I would guess the result wouldn't be exactly what is expected. On the other hand, depending on exactly git browse does with its arguments, git browse . is probably essentially equivalent to git browse $PWD. They at least reference the same directory.

How to use WinMerge with "Github for Windows"

I use "Github for Windows" as the git client (and use it with an enterprise github server). Is it possible to configure using WinMerge to be used with this client? I have not seen a setting for setting up any GUI diff tool for that matter.
In C:\Users"name of user" folder open file .gitconfig and write
[merge]
tool = winmerge
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[mergetool "winmerge"]
name = WinMerge
trustExitCode = true
cmd = "\"C:/Program Files (x86)/WinMerge/WinMergeU.exe\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" >/dev/null 2>&1"
keepBackup=false
Then,
restart github desktop,
in left pannel :
select repository :
right click : Open in Command Prompt.
When the command prompt appears type: git mergetool
If it doesn't work, try : git mergetool –tool=winmerge

Merging files in Sublime with Sublimerge via command line

I'm trying to find a better merge file option and wanted to try out Sublime as of my work is done using it. so I installed Sublimerge and now am stuck. I know I can compare two already open files or compare via the Sidebar but what I want to do is fire it off via the command line so I can kick it off from our source control program like I can with every other merge tool I've seen. Does anyone know the command line format to do this?
N.B. - I've long since given up trying to use sublime to handle merges and instead switched to other tools to handle this. Therefore I've never felt I can accept any answer as I'm not checking them to see if they work in the way I'd want, or indeed whether they work at all.
subl -n --wait "<LEFT>" "<RIGHT>" --command "sublimerge_diff_views {\"left_read_only\": true, \"right_read_only\": true}"
See "VCS Integration" for details.
As Nickolay already suggested, this is the whole directive you have to put in your ~/.gitconfig:
[merge]
tool = sublimerge
[mergetool "sublimerge"]
cmd = subl -n --wait \"$REMOTE\" \"$BASE\" \"$LOCAL\" \"$MERGED\" --command \"sublimerge_diff_views\"
trustExitCode = false
[diff]
tool = sublimerge
[difftool "sublimerge"]
cmd = subl -n --wait \"$REMOTE\" \"$LOCAL\" --command \"sublimerge_diff_views {\\\"left_read_only\\\": true, \\\"right_read_only\\\": true}\"
Taking jnns' answer, but making appropriate changes for windows.
%USERPROFILE%\.gitconfig:
[merge]
tool = sublimerge
[mergetool "sublimerge"]
cmd = sublime_text -n --wait \"$REMOTE\" \"$BASE\" \"$LOCAL\" \"$MERGED\" --command \"sublimerge_diff_views\"
trustExitCode = false
[diff]
tool = sublimerge
[difftool "sublimerge"]
cmd = sublime_text -n --wait \"$REMOTE\" \"$LOCAL\" --command \"sublimerge_diff_views {\\\"left_read_only\\\": true, \\\"right_read_only\\\": true}\"
note location of .gitconfig
in windows, the executable is sublime_text.exe, NOT subl
don't forget to add sublime text executable to the path
I'm not sure exactly how to do it, but I'm getting closer.
First, you need a handy path to the Sublime binary:
mkdir ~/bin
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Then, in your git GUI or git command line, configure ~/bin/subl as your merge tool.
I use Source Tree, and I haven't figured exactly how to best use Sublimerge, but I managed to open both versions, merge them, and then I have to do a bit of manual work.
Still not smooth, but better than nothing!