f1a6na
Last Updated: February 25, 2016
·
3.281K
· magnetikonline
Df1412e1775840374894798d5ed9a7ea

Git difftool'in like a boss

So you have been using git for a while and learning to quickly read diff patch output becomes second nature, but sometimes git difftool is what you need for those bigger changesets, calling on your configured GUI diffing tool for the job. But playing the Yes/No game with each modified file in your working copy can become tedious at times.

Discovered a rather spiffy new option with git difftool the other day for git version 1.7.11 and up and thought I would share it around.

git difftool -d

Instead of opening your GUI diff tool once per file, this new -d switch (or --dir-diff) will:

  • Copy original files at HEAD to a "left" temp directory
  • Copy all modified files to a "right" temp directory
  • Envoke your GUI diff tool comparing left vs. right directory.

Assuming you are using a diff tool that can handle directories (such as the excellent Meld), you can now compare all your files in a single GUI tool session. As a bonus, any edits you make to files in the "right" folder during the diff session will be automatically copied back to the working copy once you exit your GUI diff tool. How cool is that?!

As I'm currently using Ubuntu 12.04LTS, which comes with an edition of git below the required 1.7.11, you can add the following PPA to fetch the latest stable versions of git as they become available (1.8.0 at time of writing).

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git

I have added this to my global .gitconfig like so...

$ git config --global diff.tool 'meld'
$ git config --global alias.da 'difftool -d'

Now I can invoke this new difftool mode with a simple git da (diff all).

Like a boss indeed....

Say Thanks
Respond
Filed Under