Ubuntu - Configure Git to Use Meld for Diffs
By default, git will show you diffs in the CLI in a single view, rather than split view. I'm not elite enough to be able to work this way. This tutorial will show you how to configure git to make use of meld to have a split-pane view of your changes.
Steps
Install Meld
Install meld if you haven't already got it. Ubuntu/Debian users can simply run:
sudo apt-get install meld -y
Dixon Dick from the comments pointed out that Mac users can use homebrew to install meld from a tap:
brew install homebrew/gui/meld
Configure Git
After having installed meld, run the following command to configure git to make use of meld.
curl -s https://scripts.programster.org/scripts/9?output=raw | bash
Alternatively, copy,paste, and execute the following bash script to do the same thing.
# Write a script to run meld for git diffs.How to: Meld for Git diffs in Ubuntu Hardy
cat << EOF > /tmp/git-meld-diff
#!/usr/bin/python
import sys
import os
os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))
EOF
sudo mv /tmp/git-meld-diff /usr/bin/git-meld-diff
# Set the script to be executeable
sudo chmod +x /usr/bin/git-meld-diff
# configure git to use the new script when we run git diff.
git config --global diff.external git-meld-diff
Now when you want to view changes you have made to any files you can run:
git diff
or if you just want to view changes in one file:
git diff [filename]
Using Meld For Merge Conflicts
You probably want to also use meld for resolving merge conflicts. You can set it to do so with:
git config --global merge.tool meld
References
- How to: Meld for Git diffs in Ubuntu Hardy
- Setting up and using Meld as your git difftool and mergetool
First published: 16th August 2018