Reset external diff tool per command
Asked Answered
G

1

3

I've recently installed a new diff tool (difftastic), which messes with my habit of copying diffs to clipboard (or to file) to send those:

[diff]
    external = difft # As per https://difftastic.wilfred.me.uk/git.html
                                | what I want | what I get |
                                | ----------- | ---------- |
$ git diff                      | difft       | difft      |
$ git diff > some-file          | git diff    | difft      |
$ GIT_EXTERNAL_DIFF= git diff   | git diff    | error      |

My end goal is to have a single command to which I can pass usual git diff arguments and get the original (something like git diff --internal basically.

Eventually I'll go upstream to difftastic and offer a PR fixing that (e.g. difftastic defaulting to using git if piped), but I'm almost certain I don't understand correctly git's diff.external and difftool* configs. And I don't know how to reset diff.external per command

Gardener answered 2/8, 2022 at 9:32 Comment(4)
The manual seems pretty helpful, difftastic.wilfred.me.uk/git.html And of course an alias can make things simpler to type.Balbo
@Balbo sorry I must be a bit dull then, but I've read this manual many times and I'm not sure how it might help with my question... I want to default to git diff being difft (hence the git config --global diff.external difft), but have a solution to override that when piping, and that is where I struggle. Sorry if the question is not clear enough, I could try editing further..Gardener
That is why I suggest, instead of defaulting, use a git alias so you can easily summon difft using git syntax when desired...? But maybe that's not useful?Balbo
If possible I'd like to keep difftastic as default as there are a lot of git commands that are affected by difftools, and the only one I care about not being difftasting is git diff ^^.Gardener
G
3

A partial solution I found thanks to matt's comments on the question:

git diff --no-ext-diff

Yet I'm sure there are cleaner solution to better choose between either git diff is piped, hence use normal patch or git diff isn't hence do the fancy thing.

Gardener answered 2/8, 2022 at 10:21 Comment(4)
Yeah, I understand what you're saying about "a lot of git commands", but I still did it the other way: I created aliases, one for each command for which I want difft as a possibility. So for example git difft ... is just an alias for the rather clumsy GIT_EXTERNAL_DIFF=difft git diff .... And so on. So that way if I want old-fashioned git diff I just say git diff.Balbo
@Balbo I've clarified my intention a lot more, and since this completely changed from before, I decided to make it another question: https://mcmap.net/q/1824217/-allow-different-behaviour-for-external-diff-tool-if-git-command-is-piped/6320039, hope this is clearer.Gardener
Good idea. Might want to delete this one. :)Balbo
Please don't delete this one, it's a useful question and a useful answer.Rinderpest

© 2022 - 2024 — McMap. All rights reserved.