| by Arround The Web | No comments

Show a side-by-side git diff on any commit in tig using Meld

Side-by-side diffs are more readable to me than in-line diffs. Long time ago, I started using Meld to display them when working with git. But I always needed to manually specify branch or commit names. This week I finally spent some time and found a way to invoke Meld directly from tig, so that I can see the diff side-by-side while browsing a commit history in tig (for example, when I want to review a proposed branch containing 10 new commits, and I want to inspect each of them individually). Here’s a short howto.

First, let’s configure Meld as your git difftool:

git config --global diff.tool meld

You can now see a diff between two branches/commits with:

git difftool -d branch1 branch2

That’s a lot of typing, though, so let’s create a handy alias:

git config --global alias.dt 'difftool -d'

And now you can use:

git dt branch1 branch2

And now, let’s integrate this into tig. Edit ~/.config/tig/config and add this snippet:

# use difftool to compare a commit in main/diff view with its parent
# https://github.com/jonas/tig/issues/219#issuecomment-406817763
bind main w !git difftool -d %(commit)^!
bind diff w !git difftool -d %(commit)^!

Notice I chose the “w” key as a shortcut key, because it’s unassigned by default. You can choose a different shortcut of course, see man tigrc.

Now anytime you want to see a side-by-side diff on any commit displayed in tig:

You simply press w and you’ll see the diff between the commit and its parent show up in Meld:

This improved my life a lot, perhaps it helped you as well 🙂 Cheers.

Share Button

Source: Kparal's Fedora Blog

Leave a Reply