Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hk0i opened this issue Jun 30, 2021 · 5 comments
Open

Comments

@hk0i
Copy link

hk0i commented Jun 30, 2021

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?

@scottchiefbaker
Copy link
Contributor

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.

@OJFord
Copy link
Member

OJFord commented Jul 1, 2021

--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.

@hk0i
Copy link
Author

hk0i commented Jul 2, 2021

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)

@phil-blain
Copy link
Contributor

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.

@OJFord
Copy link
Member

OJFord commented Jul 6, 2021

@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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants