Quantcast

git-difftool

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

git-difftool

David Aguilar
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



git-difftool.sh (13K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Matthieu Moy
David Aguilar <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

David Aguilar
On Wed, Dec 31, 2008 at 8:04 AM, Matthieu Moy <[hidden email]> wrote:

> David Aguilar <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Boyd Stephen Smith Jr.-2
On Wednesday 2008 December 31 14:11:07 you wrote:

> On Wed, Dec 31, 2008 at 8:04 AM, Matthieu Moy <[hidden email]> wrote:
> > David Aguilar <[hidden email]> 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.                     ,= ,-_-. =.
[hidden email]                     ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-'
http://iguanasuicide.net/                      \_/    

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Ping Yin
In reply to this post by Matthieu Moy
On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <[hidden email]> wrote:

> David Aguilar <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Matthieu Moy
In reply to this post by David Aguilar
"David Aguilar" <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Markus Heidelberg
In reply to this post by Ping Yin
Ping Yin, 01.01.2009:

> On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <[hidden email]> wrote:
> > David Aguilar <[hidden email]> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Markus Heidelberg
In reply to this post by Matthieu Moy
Matthieu Moy, 01.01.2009:
> "David Aguilar" <[hidden email]> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Ping Yin
In reply to this post by Markus Heidelberg
On Fri, Jan 2, 2009 at 8:04 AM, Markus Heidelberg
<[hidden email]> wrote:

> Ping Yin, 01.01.2009:
>> On Thu, Jan 1, 2009 at 12:04 AM, Matthieu Moy <[hidden email]> wrote:
>> > David Aguilar <[hidden email]> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Matthieu Moy
In reply to this post by Markus Heidelberg
Markus Heidelberg <[hidden email]> writes:

> Matthieu Moy, 01.01.2009:
>> "David Aguilar" <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

David Aguilar
On Fri, Jan 2, 2009 at 8:10 AM, Matthieu Moy <[hidden email]> 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

git-difftool (2K) Download Attachment
git-difftool-helper (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Markus Heidelberg
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

David Aguilar
On Thu, Jan 15, 2009 at 2:26 PM, Markus Heidelberg
<[hidden email]> 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)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

enso
In reply to this post by Ping Yin

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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

David Aguilar
On Fri, Jan 16, 2009 at 7:47 PM, enso <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: git-difftool

Ping Yin
In reply to this post by enso
On Sat, Jan 17, 2009 at 11:47 AM, enso <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Loading...