# git-difftool

16 messages from 2008-12-26 to 2009-01-17. Participants: David Aguilar, Matthieu Moy, Boyd Stephen Smith Jr., Ping Yin, Markus Heidelberg, enso.
Thread: https://gitlist.dev/t/16866

## David Aguilar, 2008-12-26 01:30

Subject: git-difftool
Message-ID: <20081226013021.GA15414@gmail.com>
URL: https://gitlist.dev/e/20081226013021.GA15414%40gmail.com

```
Several co-workers have found this script useful.
It's basically git-mergetool modified to operate on the git
index/worktree.  There's some things about the script that
aren't very gitish (for example, the way revargs are
processed) but it's useful nonetheless.

The usual use case for this script is when you have either
staged or unstaged changes and you'd like to see the changes
in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).

	git difftool [<filename>*]

Another use case is when you'd like to see the same
information but are comparing arbitrary commits
(this is the part where the revarg parsing could be better)

	git difftool --start=HEAD^ --end=HEAD [-- <filename>*]

The last use case is when you'd like to compare your current
worktree to something other than HEAD (e.g. a tag)

	git difftool --commit=v1.0.0 [-- <filename>*]

It's a generally useful script so I thought I'd share it here.
If others find it useful then maybe we can fix it up and ship
it along with the other useful goodies in contrib/.


enjoy,

-- 

	David



```

## Matthieu Moy, 2008-12-31 16:04

Subject: Re: git-difftool
Message-ID: <vpqhc4kz5zh.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqhc4kz5zh.fsf%40bauges.imag.fr
In-Reply-To: <20081226013021.GA15414@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

> The usual use case for this script is when you have either
> staged or unstaged changes and you'd like to see the changes
> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
>
> 	git difftool [<filename>*]

Is it not a complex way of saying

        GIT_EXTERNAL_DIFF=xxdiff git diff

?

(My 2 cents, and happy new year ;-)

-- 
Matthieu

```

## David Aguilar, 2008-12-31 20:11

Subject: Re: git-difftool
Message-ID: <402731c90812311211p548c49d3p100f79ddee7163b0@mail.gmail.com>
URL: https://gitlist.dev/e/402731c90812311211p548c49d3p100f79ddee7163b0%40mail.gmail.com
In-Reply-To: <vpqhc4kz5zh.fsf@bauges.imag.fr>

```
On Wed, Dec 31, 2008 at 8:04 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> David Aguilar <davvid@gmail.com> writes:
>
>> The usual use case for this script is when you have either
>> staged or unstaged changes and you'd like to see the changes
>> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
>>
>>       git difftool [<filename>*]
>
> Is it not a complex way of saying
>
>        GIT_EXTERNAL_DIFF=xxdiff git diff
>
> ?
>
> (My 2 cents, and happy new year ;-)
>
> --
> Matthieu
>

Hmm... in theory, yes, but in practice, no.
xxdiff is too gimp to handle what 'git diff' hands it =)


For example:

$ GIT_EXTERNAL_DIFF=echo git diff test
test /tmp/.diff_1dh4TW 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 100644 test 0000

$ GIT_EXTERNAL_DIFF=xxdiff git diff test
xxdiff (cmdline.cpp:762):
You can specify at most 3 filenames.
Extra arguments: " 100644 test 0000000000000000000000000000000000000000 100644"
Use 'xxdiff --help' for more information.
external diff died, stopping at test.


I checked the git-diff documentation and could not find a way to
inhibit the sha1, mode, etc. args that are sent to GIT_EXTERNAL_DIFF
(nor should there be, I presume).

I'm all for finding the simplest way and GIT_EXTERNAL_DIFF seems like
the right entry point.  What I should do is change the script so that
it handles all of the choosing-a-merge-tool-logic and just have git
call it via GIT_EXTERNAL_DIFF.  That would definitely simplify the
script since 'git diff' would be handling all of the tmp file and
option processing logic.  wow, I really like that idea.  Thanks for
the tip!


Happy new year,

-- 
    David

```

## Boyd Stephen Smith Jr., 2008-12-31 21:20

Subject: Re: git-difftool
Message-ID: <200812311520.47999.bss@iguanasuicide.net>
URL: https://gitlist.dev/e/200812311520.47999.bss%40iguanasuicide.net
In-Reply-To: <402731c90812311211p548c49d3p100f79ddee7163b0@mail.gmail.com>

```
On Wednesday 2008 December 31 14:11:07 you wrote:
> On Wed, Dec 31, 2008 at 8:04 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> > David Aguilar <davvid@gmail.com> writes:
> >> The usual use case for this script is when you have either
> >> staged or unstaged changes and you'd like to see the changes
> >> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
> >>
> >>       git difftool [<filename>*]
> >
> > Is it not a complex way of saying
> >
> >        GIT_EXTERNAL_DIFF=xxdiff git diff
> >
> > ?
>
> Hmm... in theory, yes, but in practice, no.
> xxdiff is too gimp to handle what 'git diff' hands it =)

What about something like:
git diff | xxdiff -

I normally use:
git diff | kompare -

and it works fine.
-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss@iguanasuicide.net                     ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.net/                      \_/     

```

## Ping Yin, 2009-01-01 07:38

Subject: Re: git-difftool
Message-ID: <46dff0320812312338i5a3ee0cem702a6b67ef76e48c@mail.gmail.com>
URL: https://gitlist.dev/e/46dff0320812312338i5a3ee0cem702a6b67ef76e48c%40mail.gmail.com
In-Reply-To: <vpqhc4kz5zh.fsf@bauges.imag.fr>

```
On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> David Aguilar <davvid@gmail.com> writes:
>
>> The usual use case for this script is when you have either
>> staged or unstaged changes and you'd like to see the changes
>> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
>>
>>       git difftool [<filename>*]
>
> Is it not a complex way of saying
>
>        GIT_EXTERNAL_DIFF=xxdiff git diff

$ cat mydiff
#!/bin/bash
exec vimdiff $2 $5

then i run

$ GIT_EXTERNAL_DIFF=mydiff  git diff

but it gives me the error
Vim: Warning: Output is not to a terminal

$ ps -ef | grep vimdiff
ping     20284 20283  1 15:37 pts/13   00:00:00 vimdiff
/tmp/.diff_XXXQK6 index.php

```

## Matthieu Moy, 2009-01-01 17:58

Subject: Re: git-difftool
Message-ID: <vpq8wpux61c.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq8wpux61c.fsf%40bauges.imag.fr
In-Reply-To: <402731c90812311211p548c49d3p100f79ddee7163b0@mail.gmail.com>

```
"David Aguilar" <davvid@gmail.com> writes:

> Hmm... in theory, yes, but in practice, no.
> xxdiff is too gimp to handle what 'git diff' hands it =)

As done with "vimdiff" in another message, simply write a one-liner
wrapper script that calls xxdiff $2 $3, and call this wrapper script.

-- 
Matthieu

```

## Markus Heidelberg, 2009-01-02 00:04

Subject: Re: git-difftool
Message-ID: <200901020104.01522.markus.heidelberg@web.de>
URL: https://gitlist.dev/e/200901020104.01522.markus.heidelberg%40web.de
In-Reply-To: <46dff0320812312338i5a3ee0cem702a6b67ef76e48c@mail.gmail.com>

```
Ping Yin, 01.01.2009:
> On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> > David Aguilar <davvid@gmail.com> writes:
> >
> >> The usual use case for this script is when you have either
> >> staged or unstaged changes and you'd like to see the changes
> >> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
> >>
> >>       git difftool [<filename>*]
> >
> > Is it not a complex way of saying
> >
> >        GIT_EXTERNAL_DIFF=xxdiff git diff
> 
> $ cat mydiff
> #!/bin/bash
> exec vimdiff $2 $5
> 
> then i run
> 
> $ GIT_EXTERNAL_DIFF=mydiff  git diff
> 
> but it gives me the error
> Vim: Warning: Output is not to a terminal

Just the warning and everything else works? For me the display is
totally screwed up and the commands don't really work because of the
pager. I have to add GIT_PAGER="" to get it working.

Markus

```

## Markus Heidelberg, 2009-01-02 00:13

Subject: Re: git-difftool
Message-ID: <200901020113.32082.markus.heidelberg@web.de>
URL: https://gitlist.dev/e/200901020113.32082.markus.heidelberg%40web.de
In-Reply-To: <vpq8wpux61c.fsf@bauges.imag.fr>

```
Matthieu Moy, 01.01.2009:
> "David Aguilar" <davvid@gmail.com> writes:
> 
> > Hmm... in theory, yes, but in practice, no.
> > xxdiff is too gimp to handle what 'git diff' hands it =)
> 
> As done with "vimdiff" in another message, simply write a one-liner
> wrapper script that calls xxdiff $2 $3, and call this wrapper script.

This works with GUI tools, but not with console tools. GVim works, Vim
doesn't.
And invoking
    git difftool
is by far more convenient than
    GIT_EXTERNAL_DIFF=vimdiff git diff

Markus

```

## Ping Yin, 2009-01-02 01:59

Subject: Re: git-difftool
Message-ID: <46dff0320901011759ke7026d9hafe4fdde099e370b@mail.gmail.com>
URL: https://gitlist.dev/e/46dff0320901011759ke7026d9hafe4fdde099e370b%40mail.gmail.com
In-Reply-To: <200901020104.01522.markus.heidelberg@web.de>

```
On Fri, Jan 2, 2009 at 8:04 AM, Markus Heidelberg
<markus.heidelberg@web.de> wrote:
> Ping Yin, 01.01.2009:
>> On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
>> > David Aguilar <davvid@gmail.com> writes:
>> >
>> >> The usual use case for this script is when you have either
>> >> staged or unstaged changes and you'd like to see the changes
>> >> in a side-by-side diff viewer (e.g. xxdiff, tkdiff, etc).
>> >>
>> >>       git difftool [<filename>*]
>> >
>> > Is it not a complex way of saying
>> >
>> >        GIT_EXTERNAL_DIFF=xxdiff git diff
>>
>> $ cat mydiff
>> #!/bin/bash
>> exec vimdiff $2 $5
>>
>> then i run
>>
>> $ GIT_EXTERNAL_DIFF=mydiff  git diff
>>
>> but it gives me the error
>> Vim: Warning: Output is not to a terminal
>
> Just the warning and everything else works? For me the display is
> totally screwed up and the commands don't really work because of the
> pager. I have to add GIT_PAGER="" to get it working.
>

Thanks. With GIT_PAGER="" it works now.

```

## Matthieu Moy, 2009-01-02 16:10

Subject: Re: git-difftool
Message-ID: <vpq63kxofi3.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq63kxofi3.fsf%40bauges.imag.fr
In-Reply-To: <200901020113.32082.markus.heidelberg@web.de>

```
Markus Heidelberg <markus.heidelberg@web.de> writes:

> Matthieu Moy, 01.01.2009:
>> "David Aguilar" <davvid@gmail.com> writes:
>> 
>> > Hmm... in theory, yes, but in practice, no.
>> > xxdiff is too gimp to handle what 'git diff' hands it =)
>> 
>> As done with "vimdiff" in another message, simply write a one-liner
>> wrapper script that calls xxdiff $2 $3, and call this wrapper script.
>
> This works with GUI tools, but not with console tools.

Actually, it does if you call git --no-pager.

> GVim works, Vim
> doesn't.
> And invoking
>     git difftool
> is by far more convenient than
>     GIT_EXTERNAL_DIFF=vimdiff git diff

Right, but a script "git-difftool" calling the later is a one-liner,
so 2 one-liners give you the same result as the ~500 lines script
proposed. And GIT_EXTERNAL_DIFF has the great advantage of being
maintained together with git, and will most likely handle all cases
(diff between index, working tree, arbitrary commit, ...) correctly.

-- 
Matthieu

```

## David Aguilar, 2009-01-02 17:39

Subject: Re: git-difftool
Message-ID: <402731c90901020939k1a8ae795oc4cbfd0ced992aab@mail.gmail.com>
URL: https://gitlist.dev/e/402731c90901020939k1a8ae795oc4cbfd0ced992aab%40mail.gmail.com
In-Reply-To: <vpq63kxofi3.fsf@bauges.imag.fr>

```
On Fri, Jan 2, 2009 at 8:10 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
>
> As done with "vimdiff" in another message, simply write a
> one-liner wrapper script that calls xxdiff $2 $3, and call this
> wrapper script.
>
> ...
>
> Right, but a script "git-difftool" calling the later is a one-liner,
> so 2 one-liners give you the same result as the ~500 lines script
> proposed. And GIT_EXTERNAL_DIFF has the great advantage
> of being maintained together with git, and will most likely handle
> all cases (diff between index, working tree, arbitrary commit, ...)
> correctly.
>
> --
> Matthieu
>

Thanks for the feedback.  I've done exactly what you suggested.

I now have a git-difftool wrapper script that basically just sets up
the environment for git-difftool-helper.  git-difftool-helper does all
of the merge tool configuration stuff ala
http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html (it
uses the same git config variables and thus works with existing custom
commands).  If you drop them both into the same directory it should
work as-is (it munges $PATH).

It's not a two-liner (they do all that git config stuff and handle
more than just vimdiff) but it does use GIT_EXTERNAL_DIFF now, which
makes the script infinitely more useful.  This is much nicer now since
you can pass any 'git diff' options to git-difftool and it'll handle
it correctly.

The usage is simpler now too:

usage: git difftool [--no-prompt] [--tool=tool] ["git diff" options]


Thanks for your help,

-- 
    David

```

## Markus Heidelberg, 2009-01-15 22:26

Subject: Re: git-difftool
Message-ID: <200901152326.47332.markus.heidelberg@web.de>
URL: https://gitlist.dev/e/200901152326.47332.markus.heidelberg%40web.de
In-Reply-To: <402731c90901020939k1a8ae795oc4cbfd0ced992aab@mail.gmail.com>

```
David Aguilar, 02.01.2009:
> I now have a git-difftool wrapper script that basically just sets up
> the environment for git-difftool-helper.  git-difftool-helper does all
> of the merge tool configuration stuff ala
> http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html (it
> uses the same git config variables and thus works with existing custom
> commands).  If you drop them both into the same directory it should
> work as-is (it munges $PATH).
> 
> It's not a two-liner (they do all that git config stuff and handle
> more than just vimdiff) but it does use GIT_EXTERNAL_DIFF now, which
> makes the script infinitely more useful.  This is much nicer now since
> you can pass any 'git diff' options to git-difftool and it'll handle
> it correctly.
> 
> The usage is simpler now too:
> 
> usage: git difftool [--no-prompt] [--tool=tool] ["git diff" options]

Now isn't this something for contrib, David?

Markus

```

## David Aguilar, 2009-01-16 05:05

Subject: Re: git-difftool
Message-ID: <402731c90901152105q1880c5beod4146d955f04dd8b@mail.gmail.com>
URL: https://gitlist.dev/e/402731c90901152105q1880c5beod4146d955f04dd8b%40mail.gmail.com
In-Reply-To: <200901152326.47332.markus.heidelberg@web.de>

```
On Thu, Jan 15, 2009 at 2:26 PM, Markus Heidelberg
<markus.heidelberg@web.de> wrote:
> David Aguilar, 02.01.2009:
>> I now have a git-difftool wrapper script that basically just sets up
>> the environment for git-difftool-helper.  git-difftool-helper does all
>> of the merge tool configuration stuff ala
>> http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html (it
>> uses the same git config variables and thus works with existing custom
>> commands).  If you drop them both into the same directory it should
>> work as-is (it munges $PATH).
>>
>> It's not a two-liner (they do all that git config stuff and handle
>> more than just vimdiff) but it does use GIT_EXTERNAL_DIFF now, which
>> makes the script infinitely more useful.  This is much nicer now since
>> you can pass any 'git diff' options to git-difftool and it'll handle
>> it correctly.
>>
>> The usage is simpler now too:
>>
>> usage: git difftool [--no-prompt] [--tool=tool] ["git diff" options]
>
> Now isn't this something for contrib, David?
>
> Markus
>
>

It sure is.

BTW the script worked beautifully on *nix.

I later decided to give it a try on Windows and of course it didn't
work right the first time.  Once I added a check to use "git.exe"
instead of "git" then it started working again.  I'll prepare some
documentation and post a patch later tonight.

Thanks for reminding me,

-- 
    David


(p.s. Markus: sorry for the double-email -- I forgot to cc: the list)

```

## enso, 2009-01-17 03:47

Subject: Re: git-difftool
Message-ID: <1232164040173-2171934.post@n2.nabble.com>
URL: https://gitlist.dev/e/1232164040173-2171934.post%40n2.nabble.com
In-Reply-To: <46dff0320901011759ke7026d9hafe4fdde099e370b@mail.gmail.com>

```



Ping Yin wrote:
> 
> Thanks. With GIT_PAGER="" it works now.
> 

Personally, I didn't like having to screw around with environment variables
directly to get vimdiff to work. So I did the following:

1) Made a simple diff script gitvimdiff.sh:

#!/bin/env sh
vimdiff "$2" "$5"

2) git config --global diff.external ~/path/to/gitvimdiff.sh
3) git config --global pager.diff ""

Now when I run git-diff it uses vimdiff (hooray) and automatically turns the
pager off for me! Now only if I could get meld to work under cygwin.
-- 
View this message in context: http://n2.nabble.com/git-difftool-tp1814817p2171934.html
Sent from the git mailing list archive at Nabble.com.

```

## David Aguilar, 2009-01-17 04:41

Subject: Re: git-difftool
Message-ID: <402731c90901162041w2437587bsae1e6dde9384a4b3@mail.gmail.com>
URL: https://gitlist.dev/e/402731c90901162041w2437587bsae1e6dde9384a4b3%40mail.gmail.com
In-Reply-To: <1232164040173-2171934.post@n2.nabble.com>

```
On Fri, Jan 16, 2009 at 7:47 PM, enso <a.calhoon@gmail.com> wrote:
> Ping Yin wrote:
>>
>> Thanks. With GIT_PAGER="" it works now.
>>
>
> Personally, I didn't like having to screw around with environment variables
> directly to get vimdiff to work. So I did the following:
>
> 1) Made a simple diff script gitvimdiff.sh:
>
> #!/bin/env sh
> vimdiff "$2" "$5"
>
> 2) git config --global diff.external ~/path/to/gitvimdiff.sh
> 3) git config --global pager.diff ""
>
> Now when I run git-diff it uses vimdiff (hooray) and automatically turns the
> pager off for me! Now only if I could get meld to work under cygwin.
> --

Hello sir
It sounds like you were looking for exactly the patch I sent last night =)

http://article.gmane.org/gmane.comp.version-control.git/105925


With 'git difftool' you just do it once:

git config --global merge.tool vimdiff
git difftool [diff options]

The nice thing is that it supports the same configuration variables as
'git mergetool', so if you've already set things up to work correctly
with mergetool then you're already setup for difftool.

Meld.. I can't say I've used it on windows.
I have successfully used kdiff3 with msysgit, though.  I just
downloaded it and copied it to /bin.

difftool supports meld, though, so if you get a build of meld that
works then you should in theory be able to use it just by setting
merge.tool to meld.

-- 
    David

```

## Ping Yin, 2009-01-17 14:17

Subject: Re: git-difftool
Message-ID: <46dff0320901170617w620015cy2d155dc839dbdaf5@mail.gmail.com>
URL: https://gitlist.dev/e/46dff0320901170617w620015cy2d155dc839dbdaf5%40mail.gmail.com
In-Reply-To: <1232164040173-2171934.post@n2.nabble.com>

```
On Sat, Jan 17, 2009 at 11:47 AM, enso <a.calhoon@gmail.com> wrote:
>
>
>
> Ping Yin wrote:
>>
>> Thanks. With GIT_PAGER="" it works now.
>>
>
> Personally, I didn't like having to screw around with environment variables
> directly to get vimdiff to work. So I did the following:
>
> 1) Made a simple diff script gitvimdiff.sh:
>
> #!/bin/env sh
> vimdiff "$2" "$5"
>
> 2) git config --global diff.external ~/path/to/gitvimdiff.sh
> 3) git config --global pager.diff ""
>

I am not aware of these configurations, thanks.

What i current do is to use an alias to use vimdiff for diff

```
