git-difftool
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,
Signature · 1 line
David
Quoted 5 lines · David Aguilar
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 ;-)
Signature · 1 line
Matthieu
Quoted 10 lines · Matthieu Moy
Quoted 5 lines · David Aguilar
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
Quoted 9 lines
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,
Signature · 1 line
David
Quoted 8 lines · On Wednesday 2008 December 31 14:11:07 you wrote:
Quoted 7 lines · Matthieu Moy
Quoted 5 lines · David Aguilar
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>*]
Quoted 8 lines
Quoted 5 lines
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.
Signature · 4 lines
Boyd Stephen Smith Jr. ,= ,-_-. =. [email protected] ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/ \_/
Quoted 2 lines · David Aguilar
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.
Signature · 1 line
Matthieu
Matthieu Moy, 01.01.2009:
Quoted 7 lines
Quoted 2 lines · David Aguilar
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
Quoted 10 lines · Markus Heidelberg
Matthieu Moy, 01.01.2009:
Quoted 7 lines
Quoted 2 lines · David Aguilar
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.
Quoted 6 lines
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.
Signature · 1 line
Matthieu
Quoted 14 lines · Matthieu Moy
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_DIFFhas the great advantage of being maintained together with git, and will most likely handle all cases (diff between index, working tree, arbitrary commit, ...) correctly.
Quoted 3 lines
--
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,
Signature · 1 line
David
David Aguilar, 02.01.2009:
Quoted 14 lines
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_DIFFnow, 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.
Quoted 3 lines
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
Quoted 15 lines · Markus Heidelberg
David Aguilar, 02.01.2009:
Quoted 14 lines
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_DIFFnow, 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.
Quoted 9 lines
Quoted 3 lines
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,
Signature · 4 lines
David (p.s. Markus: sorry for the double-email -- I forgot to cc: the list)
Quoted 11 lines · Matthieu Moy
Quoted 5 lines · David Aguilar
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
Ping Yin, 01.01.2009:
Quoted 17 lines · Matthieu Moy
Quoted 11 lines
Quoted 5 lines · David Aguilar
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
Quoted 6 lines
then i run
$ GIT_EXTERNAL_DIFF=mydiff git diffbut 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
Quoted 20 lines · Markus Heidelberg
Ping Yin, 01.01.2009:
Quoted 19 lines · Matthieu Moy
Quoted 11 lines
Quoted 5 lines · David Aguilar
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 $5then i run
Quoted 9 lines
Quoted 4 lines
$ GIT_EXTERNAL_DIFF=mydiff git diffbut it gives me the error
Vim: Warning: Output is not to a terminalJust 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.
Quoted 3 lines · Ping Yin
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.
Signature · 2 lines
View this message in context: http://n2.nabble.com/git-difftool-tp1814817p2171934.html Sent from the git mailing list archive at Nabble.com.
Quoted 13 lines · enso
Quoted 3 lines · Ping Yin
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"
Quoted 6 lines
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.
Signature · 1 line
David
Quoted 11 lines · enso
Quoted 3 lines · Ping Yin
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:
Quoted 8 lines
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