diff-so-fancy icon indicating copy to clipboard operation
diff-so-fancy copied to clipboard

Bypass diff-so-fancy without breaking pager? (Recommended solution attached)

Open hk0i opened this issue 4 years ago • 5 comments

I was trying to figure out how to bypass diff-so-fancy for a one-off situation where I wanted a copy/pastable diff format. The instructions currently recommend:

git --no-pager diff <sh1> <sh2>

But my diff was huge so disabling a pager wasn't a very good way to go about it. I found that the GIT_PAGER env variable mentioned in man git overrides the default pager options as well.

I'm opening this ticket to suggest a new recommended way of overriding without breaking paging:

GIT_PAGER=less git diff <sh1> <sh2>

I'd ask everyone to give it a quick try to see if there are any issues with it. If we like it and you guys don't have time I can open a PR later to add it to the pro tips guide.

I figured it would be better to open a ticket first and consult before sending over a random PR.

What do you guys think of this change?

hk0i avatar Jun 30 '21 19:06 hk0i

You can also do git diff db235481a 629e7490c > /tmp/raw.diff

Anything that redirects, and thus doesn't require a pager, will be completely bypass d-s-f. Not sure which is best though.

scottchiefbaker avatar Jun 30 '21 20:06 scottchiefbaker

--paginate/-P also overrides any configured pager, which is probably a more portable/less surprising 'pro tip' since it will still respect any exported PAGER or GIT_PAGER, and people won't copy and paste it complain that 'it says command less not found' 🙂.

👍🏻 for the principle though.

OJFord avatar Jul 01 '21 17:07 OJFord

the --paginate option doesn't override dsf on my machine. I even tried using the PAGER env var mentioned in the git manual with it and it still didn't work, the only one that works for me is specifying the pager using GIT_PAGER. Is anyone else seeing that? On Mac OS X / Big Sur (will have to check exact version when I get back to my dev machine)

hk0i avatar Jul 02 '21 22:07 hk0i

I can confirm the behaviour that @hk0i describes: with core.pager = diff-so-fancy | less --tabs=4 -RFX (i.e. the recommended way to use dsf), the only way to temporarily disable dsf and still page the output is GIT_PAGER=less git diff. The following do not disable dsf:

git -p diff
PAGER=less git diff

That's what I see on Ubuntu 18, 20 and macOS 10.11.

phil-blain avatar Jul 06 '21 20:07 phil-blain

@phil-blain That should be a capital -P (or else --paginate) but I think that's not the issue here and just a typo in your comment.

If diff-so-fancy is your core.pager, that's exactly equivalent to $GIT_PAGER, hence why that's needed to override it.

If it's your pager.diff, you should see the behaviour I described, on git 2.32.0, Linux & macOS.

(What you lose by doing this is most obviously git log -p. It would be nice if git had a 'diff formatter' concept that was used for whole diffs, and diffs within logs et al. alike, but it doesn't, so d-s-f has to use the pager hook (and be explicitly configured to use whichever actual pager) leading to this sort of trade-off.)

OJFord avatar Jul 06 '21 22:07 OJFord